Jump to content

SOLVED Display List Of Data From MySql Table


RobberBaron

Recommended Posts

I'm trying to output a list from a table in MySql using PHP. The way I'm doing it used to work on other things such as memberlists, but this seems to want to output every occurance an infinite number of times. In other words, when the page loads it will have a list showing hundreds of the first row from the database and will continue trying to load it. This is the code I'm using:

While($info=mysql_fetch_array(mysql_query('SELECT * FROM projects'))) {	Echo('<li><a href="project.php?id='.$info['ID'].'" title="'.$info['title'].'">'.$info['title'].'</a>|<a onclick="$.post(\'delete.php\', {\'webid\': '.$info['ID'].'});">X</a>|</li>');};

Is it a problem with the while?

Link to comment
Share on other sites

You are executing the query over and over again, so the pointer keeps getting reset. You are supposed to create a result resource, then use mysql_fetch_array() to iterate over the resulting variable.

$result = mysql_query('SELECT * FROM projects');while($info=mysql_fetch_array($result)) {	echo('<li><a href="project.php?id='.$info['ID'].'" title="'.$info['title'].'">'.$info['title'].'</a>|<a onclick="$.post(\'delete.php\', {\'webid\': '.$info['ID'].'});">X</a>|</li>');};

Link to comment
Share on other sites

You are executing the query over and over again, so the pointer keeps getting reset. You are supposed to create a result resource, then use mysql_fetch_array() to iterate over the resulting variable.
$result = mysql_query('SELECT * FROM projects');while($info=mysql_fetch_array($result)) {	echo('<li><a href="project.php?id='.$info['ID'].'" title="'.$info['title'].'">'.$info['title'].'</a>|<a onclick="$.post(\'delete.php\', {\'webid\': '.$info['ID'].'});">X</a>|</li>');};

Ahah, makes sense. Thanks :)
Link to comment
Share on other sites

The semicolon represents an empty statement:

$result = mysql_query('SELECT * FROM projects');while($info=mysql_fetch_array($result)) {	echo('<li><a href="project.php?id='.$info['ID'].'" title="'.$info['title'].'">'.$info['title'].'</a>|<a onclick="$.post(\'delete.php\', {\'webid\': '.$info['ID'].'});">X</a>|</li>');}NULL; // a line doing nothing

As such, it is not necessary, but not syntactically incorrect.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...