Re: retrieving data from mysql table

From: Date: Sun, 10 Nov 2002 18:25:14 +0000
Subject: Re: retrieving data from mysql table
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-23189@lists.php.net to get a copy of this message
Notice that you are adding $x in the loop. You are getting a row, printing out index 0 of table_headers, incrementing $x, then moving to the next row. Basically you are fetching row 1 column 1, row 2 column 2, row 3 column 3, etc. instead of fetching all rows. Do this instead: $query = "SELECT * FROM " .$table. "" ; $result = mysql_query ( $query ) or die( mysql_error () ); while ( $row = mysql_fetch_assoc ($result)) { while(list(,$col)=each($row)) { echo "<TD>{$col}</TD>"; } } This will echo all rows, and for each row will echo all values in order of your table, which is also the order of $table_headers. Peter On Sun, 10 Nov 2002, David Rice wrote: > <? > /* Select all the records from the table */ > $query = "SELECT * FROM " .$table. "" ; > $result = mysql_query ( $query ) or die( mysql_error () ); > $x = 0 ; > while ( $row = mysql_fetch_assoc ($result)) { > ?> > <TD> > <? > echo $row[$table_headers[$x]] ; > ?> > </TD> > <? > $x++ ; > } > ?> > </TABLE> --------------------------------------------------------------------------- Peter Beckman Systems Engineer, Fairfax Cable Access Corporation beckman@purplecow.com http://www.purplecow.com/ ---------------------------------------------------------------------------

« previous php.db (#23189) next »