RobberBaron Posted September 12, 2010 Share Posted September 12, 2010 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 More sharing options...
Synook Posted September 12, 2010 Share Posted September 12, 2010 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 More sharing options...
Sami Posted September 12, 2010 Share Posted September 12, 2010 I didn't know that semicolon were allowed after the "}". Link to comment Share on other sites More sharing options...
RobberBaron Posted September 12, 2010 Author Share Posted September 12, 2010 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 More sharing options...
Synook Posted September 13, 2010 Share Posted September 13, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.