Re: A better way of displaying query

From: Date: Tue, 01 Aug 2000 23:15:59 +0000
Subject: Re: A better way of displaying query
Groups: php.general 
Request: Send a blank email to php-general+get-9596@lists.php.net to get a copy of this message
> I'm following an example in PHP essentials that shows how to display mysql > database info in a HTML table. What I need to display is a mysql table that > has over 20 columns and I want to know an easier way. Here is an example of > what I have. > > while ($row = mysql_fetch_array($sql_result)) { > $item1 = $row["item1"]; > $item2 = $row["item2"]; > $item3 = $row["item3"]; > $item4 = $row["item4"]; > etc,etc,etc > > echo > "<TR><TD>$item1</TD><TD>$item2</TD><TD>$item3</TD><TD>$item4</TD> > etc,etc,etc > } > > Is there a better way? Such as: > > while ($row = mysql_fetch_array($sql_result)) { > $items = $row["*"]; If your needs are that simple, why not use something like this: echo '<TR><TD>' . implode($row, '</TD><TD>') . '</TD></TR>' Unfortunately, I find that's rarely the case. I'm still confused by the syntax you use above as I'd use something like: echo "<TR><TD>{$row['item1']}</TD><TD>{$row['item1']}" (Note that you can wrap associate array references in {} to have PHP parse the entire think instead of just the array reference.)

« previous php.general (#9596) next »