Jump to content

best way to list everything in a table?


android6011

Recommended Posts

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 :)

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
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.