stvchez Posted January 30, 2007 Share Posted January 30, 2007 I'm trying to loop data results and alittle stuck. $query = "SELECT * FROM aeWorkoutRuns where username='$username'"; $result = mysql_query($query, $link); // get number of rows$num=mysql_numrows($result); // set variables $run_title=mysql_result($result,$i,"run_title");$route_url=mysql_result($result,$i,"route_url"); // Write the Name and Age inserted into Mysql Databaseecho "<table width=400><tr><td>Run Title</td><td>Route URL</td></tr>";$i=0;while ($i < $num) {echo "<tr><td>";echo "$run_title </td><td>";echo "$route_url </td></tr>";$i++;}echo "</table>";?>///////////////this is what I get:Run Title Route URLLos Altos Loop #5 gmap.loop.number5Los Altos Loop #5 gmap.loop.number5These should be unique. thanks. Link to comment https://forums.phpfreaks.com/topic/36368-newbie-data-looping/ Share on other sites More sharing options...
Tandem Posted January 30, 2007 Share Posted January 30, 2007 You need to set the variables inside the loop. Link to comment https://forums.phpfreaks.com/topic/36368-newbie-data-looping/#findComment-172967 Share on other sites More sharing options...
paul2463 Posted January 30, 2007 Share Posted January 30, 2007 [code]<?php$num=mysql_num_rows($result); //this will get a better answer for number of rows than yours?>[/code] Link to comment https://forums.phpfreaks.com/topic/36368-newbie-data-looping/#findComment-172968 Share on other sites More sharing options...
stvchez Posted January 30, 2007 Author Share Posted January 30, 2007 re: putting the variable inside the loop, isn't this correct:while ($i < $num) {echo "<tr><td>";echo "$run_title </td><td>";echo "$route_url </td></tr>";$i++;}if not, would it be possible to post an example. thx Link to comment https://forums.phpfreaks.com/topic/36368-newbie-data-looping/#findComment-172972 Share on other sites More sharing options...
paul2463 Posted January 30, 2007 Share Posted January 30, 2007 [code]<?phpwhile ($i < $num) {$run_title=mysql_result($result,$i,"run_title");$route_url=mysql_result($result,$i,"route_url");echo "<tr><td>";echo "$run_title </td><td>";echo "$route_url </td></tr>";$i++;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/36368-newbie-data-looping/#findComment-172976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.