PHPiSean Posted August 31, 2011 Share Posted August 31, 2011 Here's the code, I had used the query in the header, and now I'm using it to display the links in a table. What happens is that it only returns the first row and not the second third or fourth rows. When it does display the first row, it'll display it a lot of times. Here it is <?php if($_GET['place']==addnetwork){ //display current networks echo "<table border=1>"; echo "<tr><td>Network Name</td><td>URL</td></tr>"; while ($query1 = mysql_fetch_assoc(mysql_query("select name,url from s_links"))) { $networkname = $query1['name']; $networkurl = $query1['url']; echo "<tr><td>$networkname</td><td>$networkurl</td></tr>"; } echo "</table>"; } ?> Quote Link to comment Share on other sites More sharing options...
samshel Posted August 31, 2011 Share Posted August 31, 2011 <?php if($_GET['place']==addnetwork){ //display current networks echo "<table border=1>"; echo "<tr><td>Network Name</td><td>URL</td></tr>"; $result = mysql_query("select name,url from s_links"); while ($query1 = mysql_fetch_assoc($result)) { $networkname = $query1['name']; $networkurl = $query1['url']; echo "<tr><td>$networkname</td><td>$networkurl</td></tr>"; } echo "</table>"; } ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 31, 2011 Share Posted August 31, 2011 That loop will continue indefinitely! You need to run the query ONE TIME and then do a while loop over the RESULTS. You are currently running a new query on each iteration of the loop and only getting the first result. if($_GET['place']==addnetwork) { //Create/execute query $query = "SELECT name, url FROM s_links"; $result = mysql_query($query) or die("Error running query: " . mysql_error()); //display current networks echo "<table border=1>\n"; echo "<tr><th>Network Name</th><th>URL</th></tr>\n"; //Loop through results while ($row = mysql_fetch_assoc$result()) { echo "<tr><td>{$row['name']}</td><td>{$row['url']}</td></tr>\n"; } echo "</table>\n"; } Quote Link to comment Share on other sites More sharing options...
PHPiSean Posted August 31, 2011 Author Share Posted August 31, 2011 thanks guys! Worked perfectly. I'll remember this for next time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.