RE: Select statement with Array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I have the following code(minus the connection to the database):
> 
> $query = @mysql_query("SELECT
>
ID,lastname,frstname,address,city,state,zipcode,homephne,email,employ,oc
cp
> tn
> ,workphne,housetype,usher830 from database.talents WHERE ID=\"4\";");
> while ($usher = mysql_fetch_array($query)) {

At this point, $usher is just an array. You can loop through it and
apply htmlspecialchars() to each element using a foreach() loop or
array_walk().

>    $lastname = htmlspecialchars($usher["lastname"]);
>    $frstname = htmlspecialchars($usher["frstname"]);
>    $address = htmlspecialchars($usher["address"]);
>    $usher830 = htmlspecialchars($usher["usher830"]);
> 
>    print("<table border=\"2\"><tr>");
>    print("<td>$frstname $lastname</td>");
>    print("<td>$address</td>");
>    print("</tr>");
>    if ($usher830 == 1) {
>       print("<tr><td>$title[16]</td></tr>");

I don't understand how $usher830 and $title[16] are related, but like I
said before, $usher is an array, so you can loop through each element,
check the key and if it's in the 'usherXXX' format (???) then display
some element of $title...

>    }
>    print("</table>");
> }
> 
> I want to be able to connect to the table in the database and pull
> information from each field and if it is equal to 1 (true, user
selected
> this) print out a certain phrase.  This all works, the only problem is
I
> have over 100 fields and it would be a very large file do all of this
like
> I
> am currently doing.  Is there a way to loop the top part with the
> htmlspecialchars part and then also the if statement at the bottom?  I
cut
> down the SELECT statement to show the necessary part, there is more to
it.

Hope that helps. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux