Re: A better way of displaying query

From: Date: Tue, 01 Aug 2000 23:55:34 +0000
Subject: Re: A better way of displaying query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-9603@lists.php.net to get a copy of this message
Mike Tuller wrote: > > 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["*"]; Remember, there's always more than one (or 10, or 30) ways to do something. Just so you know (since you're reading my book -- thanks!)...I tend to use very verbose examples in order to make a point. It's the "beat the meaning into your head" example that I picked up in Catholic school as a young child. :) That being said, if naming the explicit variable is just too much typing, then you could use the mysql_num_fields() function to get a total number of fields return in the row, then increment upwards to that number. Or about 10 or 30 other ways, I'm sure you'll read. :) - julie +------------------------------------------------+ | Julie Meloni (jcm@i2ii.com) | | Tech. Director, i2i Interactive (www.i2ii.com) | | | | "PHP Essentials" & "PHP Fast & Easy" | | http://www.thickbook.com/ | +------------------------------------------------+

« previous php.general (#9603) next »