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 Link to comment https://forums.phpfreaks.com/topic/157368-solved-auto-number-table-rows-in-dynamic-table/ 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 Link to comment https://forums.phpfreaks.com/topic/157368-solved-auto-number-table-rows-in-dynamic-table/#findComment-829501 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>"; Link to comment https://forums.phpfreaks.com/topic/157368-solved-auto-number-table-rows-in-dynamic-table/#findComment-829505 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. Link to comment https://forums.phpfreaks.com/topic/157368-solved-auto-number-table-rows-in-dynamic-table/#findComment-829507 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 Link to comment https://forums.phpfreaks.com/topic/157368-solved-auto-number-table-rows-in-dynamic-table/#findComment-829524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.