Daney11 Posted January 25, 2007 Share Posted January 25, 2007 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 goes123456Etc...I usedfor ($i=1; $i <21; $i++){echo $i}But that echoed out my rows 20 times each.Thanks Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 25, 2007 Share Posted January 25, 2007 Please post the code that is giving you problems.Ken Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 25, 2007 Author Share Posted January 25, 2007 [code]<table width="639" cellpadding="0" cellspacing="0" align="center"><tr> <td height="20" colspan="10" class="leagueoutline"> <strong>English Premiership</strong></td></tr><tr> <td width="28" height="20" align="center" class="leagueoutline"> </td><td width="176" height="20" align="left" class="leagueoutline"> Team Name</td><td width="153" height="20" align="left" class="leagueoutline"> 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"> <?php echo stripslashes($myrow['team_name']); ?></td><td height="20" align="left" class="leagueoutline"> 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] Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 25, 2007 Author Share Posted January 25, 2007 [code]<?phpfor ($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. Quote Link to comment Share on other sites More sharing options...
matto Posted January 25, 2007 Share Posted January 25, 2007 [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"> <?php echo stripslashes($myrow['team_name']); ?></td><td height="20" align="left" class="leagueoutline"> 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] ;) Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 25, 2007 Author Share Posted January 25, 2007 Thanks a lot matto, That worked perfect. Quote Link to comment Share on other sites More sharing options...
matto Posted January 25, 2007 Share Posted January 25, 2007 Don't forget to set this to resolved... Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 26, 2007 Author Share Posted January 26, 2007 Im not sure how to do it, I cannot see the resloved button to click? :S 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.