Jump to content

[SOLVED] Auto Number table rows in dynamic table


PHP_Idiot

Recommended Posts

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

 

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>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.