PDA

View Full Version : displaying all rows in mysql database


nabberuk
10-27-2002, 07:12 PM
how would i go about this, i have already found out how to count how many rows are in the table, so i think i just need a while statement, problem is, i dont know how to output each field of the row.

so any help would be good.





im sorry for my previous posts, there were not clear enough and i may of given some incorrect information.


thanks

inks
11-23-2002, 09:01 AM
If you've got a table called members, with the fields memberID and membername, this will roll out the whole lot into HTML format:

<table>

<tr><td>memberID</td><td>membername</td></tr>

<?

$sql="select memberID, membername from members;";

$result=mysql_query($sql);

while($row=mysql_fetch_row($result))

{

printf("<tr><td>%s</td><td>%s</td></tr>",$row[0],$row[1]);

}

?>

</table>

You might like to look at SELECT SYNTAX in the mySQL manual and the mysql_query(), mysql_fetch_array() and printf() functions in the PHP manual to work out what's going on in the code.