Jump to content

[SOLVED] $position+1 Help


Daney11

Recommended Posts

Hey Guys,

Basically, i have 20 rows in my database and i have created a league table for those rows. I need a formula to echo out the position of the row. For example...

$Position = 1;

Echo $Position+1, so my table goes

1
2
3
4
5
6
Etc...

I used

for ($i=1; $i <21; $i++){

echo $i

}

But that echoed out my rows 20 times each.

Thanks
Link to comment
https://forums.phpfreaks.com/topic/35731-solved-position1-help/
Share on other sites

[code]
<table width="639" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="20" colspan="10" class="leagueoutline">&nbsp;<strong>English Premiership</strong></td>
</tr>
<tr>
<td width="28" height="20" align="center" class="leagueoutline">&nbsp;</td>
<td width="176" height="20" align="left" class="leagueoutline">&nbsp;Team Name</td>
<td width="153" height="20" align="left" class="leagueoutline">&nbsp;Manager</td>
<td width="28" height="20" align="center" class="leagueoutline">Pld</td>
<td width="28" height="20" align="center" class="leagueoutline">Won</td>
<td width="28" height="20" align="center" class="leagueoutline">Drn</td>
<td width="28" height="20" align="center" class="leagueoutline">Lst</td>
<td width="60" height="20" align="center" class="leagueoutline">For-Ag</td>
<td width="28" height="20" align="center" class="leagueoutline">Pts</td>
<td width="60" height="20" align="center" class="leagueoutline">Form</td>
</tr>
<?php

$strQuery = "SELECT * FROM teams WHERE team_league = 'Premiership'";
$result = mysql_query($strQuery,$db) or die(mysql_error());

while ($myrow = mysql_fetch_array($result))

{


?>
<tr>
<td height="20" align="center" class="leagueoutline"><? echo $position ?></td>
<td height="20" align="left" class="leagueoutline">&nbsp;<?php echo stripslashes($myrow['team_name']); ?></td>
<td height="20" align="left" class="leagueoutline">&nbsp;Manager</td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($myrow['team_matches_played']); ?></td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($team_win_total); ?></td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($team_draw_total); ?></td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($team_lose_total); ?></td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($team_total_goals_for); ?> - <?php echo stripslashes($team_total_goals_against); ?></td>
<td height="20" align="center" class="leagueoutline">Pts</td>
<td height="20" align="center" class="leagueoutline">Form</td>
<?php

}

?>
</tr>
</table>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/35731-solved-position1-help/#findComment-169317
Share on other sites

[code]<?php

for ($position=1; $position < 21; $position++)

{

echo "$position";

}

?>
[/code]

That echos out the numbers 1 to 20.

However when i enter that into my code, all 20 rows in my database like to take each of those numbers for themselves, so each row in the database has all the numbers from 1 to 20.
Link to comment
https://forums.phpfreaks.com/topic/35731-solved-position1-help/#findComment-169338
Share on other sites


[code]
<?php
....
$position = 1;
while ($myrow = mysql_fetch_array($result))

{


?>
<tr>
<td height="20" align="center" class="leagueoutline"><? echo $position ?></td>
<td height="20" align="left" class="leagueoutline">&nbsp;<?php echo stripslashes($myrow['team_name']); ?></td>
<td height="20" align="left" class="leagueoutline">&nbsp;Manager</td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($myrow['team_matches_played']); ?></td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($team_win_total); ?></td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($team_draw_total); ?></td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($team_lose_total); ?></td>
<td height="20" align="center" class="leagueoutline"><?php echo stripslashes($team_total_goals_for); ?> - <?php echo stripslashes($team_total_goals_against); ?></td>
<td height="20" align="center" class="leagueoutline">Pts</td>
<td height="20" align="center" class="leagueoutline">Form</td>
<?php
$position++;
}

?>

[/code]

;)
Link to comment
https://forums.phpfreaks.com/topic/35731-solved-position1-help/#findComment-169339
Share on other sites

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.