Re: Select statement with Array
| From: | olinux | Date: | Fri, 18 Apr 2003 04:17:55 +0000 |
| Subject: | Re: Select statement with Array | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27154@lists.php.net to get a copy of this message | ||
Here's my suggestion -
while ($usher = mysql_fetch_array($query))
{
/* assign values the prefix "_" is not necessary
** but may help avoid overwriting existing values
** i.e. lastname field will be $_lastname
*/
foreach ($row as $k => $v)
{
$$_k = htmlentities(stripslashes($v));
}
/* shortened if/else statement
** if statement is true $_usher830 becomes the first
value
*/
$_usher830 = ($_usher830 == 1) ? $title[16] : 'No';
echo '<table border="2">
<tr>
<td>'.$_frstname.' '.$_lastname.'</td>
<td>'.$_address.'</td>
</tr>
<tr>
<td>'.$_usher830.'</td>
</tr>
</table>';
}
olinux
--- Mark <mneemann@neb.rr.com> wrote:
> 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,occptn
> ,workphne,housetype,usher830 from database.talents
> WHERE ID=\"4\";");
> while ($usher = mysql_fetch_array($query)) {
> $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>");
> }
> 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.
>
> Thanks.
> Mark
__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com