RDKL PerFecT Posted April 8, 2006 Share Posted April 8, 2006 Hi there, this is my code// Perform MySQL query on only the current page number's results. The problem is it doesn't echo anything at all now, since I've tried to add this nrows thing to make each result numbered, any help would be greatly appreciated.[code]$sql = mysql_query("SELECT * FROM Players ORDER BY Points DESC LIMIT $from, $max_results");for ($i=0;$i<$nrows;$i++) { $n = $i +1; //add 1 so that numbers don't start with 0 $row = mysql_fetch_array($sql); extract($sql); // Build your formatted results here. echo("<tr bgcolor=".$bgcolor."><td>"); echo($row["Name"]); echo("</td><td>"); echo($row["Nationality"]); echo("</td><td>"); echo($row["Points"]); echo("</td></tr>"); }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6899-php-row-problem/ Share on other sites More sharing options...
IceHawk Posted April 9, 2006 Share Posted April 9, 2006 Where is $nrows being set? Based just off what you posted here, $nrows doesn't exist so the loop will never run. You would need to do something like ;$nrows = mysql_fetch_rows($sql);Or you could do;[code]$sql = mysql_query("SELECT * FROM Players ORDER BY Points DESC LIMIT $from, $max_results");while($row = mysql_fetch_array($sql)){ $n = $i +1; //add 1 so that numbers don't start with 0 // Build your formatted results here. echo("<tr bgcolor=".$bgcolor."><td>"); echo($row["Name"]); echo("</td><td>"); echo($row["Nationality"]); echo("</td><td>"); echo($row["Points"]); echo("</td></tr>");}[/code]With the above, the loop will run for each row returned by the query, and each row will be entered into $row for you. So there is no need for the for loop. Quote Link to comment https://forums.phpfreaks.com/topic/6899-php-row-problem/#findComment-25132 Share on other sites More sharing options...
RDKL PerFecT Posted April 9, 2006 Author Share Posted April 9, 2006 [!--quoteo(post=362914:date=Apr 9 2006, 03:50 AM:name=IceHawk)--][div class=\'quotetop\']QUOTE(IceHawk @ Apr 9 2006, 03:50 AM) [snapback]362914[/snapback][/div][div class=\'quotemain\'][!--quotec--]Where is $nrows being set? Based just off what you posted here, $nrows doesn't exist so the loop will never run. You would need to do something like ;$nrows = mysql_fetch_rows($sql);Or you could do;[code]$sql = mysql_query("SELECT * FROM Players ORDER BY Points DESC LIMIT $from, $max_results");while($row = mysql_fetch_array($sql)){ $n = $i +1; //add 1 so that numbers don't start with 0 // Build your formatted results here. echo("<tr bgcolor=".$bgcolor."><td>"); echo($row["Name"]); echo("</td><td>"); echo($row["Nationality"]); echo("</td><td>"); echo($row["Points"]); echo("</td></tr>");}[/code]With the above, the loop will run for each row returned by the query, and each row will be entered into $row for you. So there is no need for the for loop.[/quote]I've found this code from another script of how to number things, which sets $nrows like you said. I now get it to each "$n.", which just shows up as 1. for each row instead of 1,2,3,4 etc. Any way I can fix this?[code]$query = "SELECT url,linkname,id,description,hits FROM Links WHERE ok='1' ORDER by url desc"; $result = mysql_query($query) or die ("Couldn't execute query.");$nrows = mysql_num_rows($result);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6899-php-row-problem/#findComment-25173 Share on other sites More sharing options...
IceHawk Posted April 10, 2006 Share Posted April 10, 2006 If you're using my while loop, there's a slight mistake I just noticed. If you replace$n = $i + 1;with;$n = $i++ + 1;Then you should be good to go. Quote Link to comment https://forums.phpfreaks.com/topic/6899-php-row-problem/#findComment-25384 Share on other sites More sharing options...
RDKL PerFecT Posted April 10, 2006 Author Share Posted April 10, 2006 [!--quoteo(post=363174:date=Apr 10 2006, 04:07 AM:name=IceHawk)--][div class=\'quotetop\']QUOTE(IceHawk @ Apr 10 2006, 04:07 AM) [snapback]363174[/snapback][/div][div class=\'quotemain\'][!--quotec--]If you're using my while loop, there's a slight mistake I just noticed. If you replace$n = $i + 1;with;$n = $i++ + 1;Then you should be good to go.[/quote]Thank you.Ok, That's sorted, I then have one final problem. When a new page starts (e.g. board(1).php?page=2) it re-starts the counter from 1, instead of what effectively should be 16. Check [a href=\"http://www.rdkleague.com/marathon/board(1).php\" target=\"_blank\"]This Page[/a] to see what the hell I'm on about. Again, thanks for any help you can offer. Quote Link to comment https://forums.phpfreaks.com/topic/6899-php-row-problem/#findComment-25464 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.