PHP_Idiot Posted May 8, 2009 Share Posted May 8, 2009 Hi All I'm sure this is simple but I can't get it working. I have an html table on my site that draws data from my database it all works very nicely, but I've decided that I now need to number the rows 1,2,3,4 etc I know this will need a loop and something like a $counter++ but I can't get it working. This is my current table including the query: //mySQL queries $query = "SELECT SUM(Position.Points) , Player.FirstName, Player.LastName, COUNT(Results.MembershipNo) FROM Position, Player, Results, Venue WHERE Player.MembershipNo = Results.MembershipNo AND Results.Position = Position.Position AND Venue.VenueID = Results.VenueID GROUP BY Player.MembershipNo ORDER BY SUM(Position.Points) DESC"; $result=mysql_query($query) or die ("couldn't execute query"); echo <<<html <table border="1" width="400" cellpadding="2" cellspacing="1"> <tr><td align="center"><strong>Position</strong></td> <td align="center"><strong>Total Points</strong></td> <td align="center"><strong>First Name</strong></td> <td align="center"><strong>Last Name</strong></td> <td align="center"><strong>Games Played</strong></td> </tr> html; //Now start the loop. while($r = mysql_fetch_array($result)){ //and echo each new row echo <<<html <tr><td align="center">I WANT TO AUTONUMBER THIS ROW</td> <td align="center">{$r['SUM(Position.Points)']}</td> <td align="center">{$r['FirstName']}</td> <td align="center">{$r['LastName']}</td> <td align="center">{$r['COUNT(Results.MembershipNo)']}</td> </tr> html; } //And close the table. echo "</table>"; I have tried adding $pos=1; $pos++; and then $pos in the table row but that returns '2' on every row. Thanks in advance Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Hello Idiot, Can you put your $pos back in the code so we can see if you did it right? Ken Quote Link to comment Share on other sites More sharing options...
PHP_Idiot Posted May 8, 2009 Author Share Posted May 8, 2009 Sure thing, this is how I had added it, as I said this just returns '2' on every line! //Now start the loop. $pos=1; $pos++; while($r = mysql_fetch_array($result)){ //and echo each new row echo <<<html <tr><td align="center">$pos</td> <td align="center">{$r['SUM(Position.Points)']}</td> <td align="center">{$r['FirstName']}</td> <td align="center">{$r['LastName']}</td> <td align="center">{$r['COUNT(Results.MembershipNo)']}</td> </tr> html; } //And close the table. echo "</table>"; Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 :-\ Wow... that was genius dude! Move $pos++ to the end of your while loop. Quote Link to comment Share on other sites More sharing options...
PHP_Idiot Posted May 8, 2009 Author Share Posted May 8, 2009 They don't call me PHP_Idiot for nothing you know Thanks a lot, I guessed it was something simple. Works a treat now. Cheers 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.