android6011 Posted April 11, 2008 Share Posted April 11, 2008 is this ok or is there a better way? $query = "SELECT * FROM stuff ORDER BY 'id'"; $result=mysql_query($query); $i=0; $num=mysql_numrows($result); while ($i < $num) { $info=mysql_result($result,$i,"theinfo"); print "$info"; $i++; } Link to comment https://forums.phpfreaks.com/topic/100593-best-way-to-list-everything-in-a-table/ Share on other sites More sharing options...
The Bat Posted April 11, 2008 Share Posted April 11, 2008 If I understand what you're talking about (fetching records from a table), then I think this is what you want... $query = mysql_query("SELECT * FROM stuff ORDER BY 'id'"); while ($row = mysql_fetch_array($query)) { echo $row['column_name']; echo $row['different_column_name']; # etc... } Much easier Link to comment https://forums.phpfreaks.com/topic/100593-best-way-to-list-everything-in-a-table/#findComment-514488 Share on other sites More sharing options...
android6011 Posted April 11, 2008 Author Share Posted April 11, 2008 thank you i appreciate it Link to comment https://forums.phpfreaks.com/topic/100593-best-way-to-list-everything-in-a-table/#findComment-515266 Share on other sites More sharing options...
soycharliente Posted April 12, 2008 Share Posted April 12, 2008 Make sure you check to see that your MySQL resource has rows in it before you start looping through them. <?php $sql = "SELECT * FROM `table`"; $result = mysql_query($sql) OR DIE (mysql_error()); if (mysql_num_rows($result)) // RIGHT HERE! { while ($row = mysql_fetch_assoc($result)) { // do stuff } } ?> Link to comment https://forums.phpfreaks.com/topic/100593-best-way-to-list-everything-in-a-table/#findComment-515284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.