lukep11a Posted July 17, 2011 Share Posted July 17, 2011 Hi, I have a working league table where each persons name, team name and number of points is displayed, it also sorts them in order of points, does anybody know how would I get the position number each person is in to be displayed in the place of <td width="50">'team position here'</td> ? Any help would be much apreciated. <table width="350" border="0" cellpadding="0" cellspacing="0" class="myteams"> <tr class="title"> <td width="50">Position</td> <td width="250">Name</td> <td width="250">Team Name</td> <td width="50">Points</td> </tr> <?php $query = "SELECT privateleague.privateleagueid, privateleague.privateleaguename, user_leagues.privateleagueid, user_leagues.userid, login.userid, login.forename, login.surname, login.teamname, selections.userid, SUM(teams.points) FROM privateleague, user_leagues, login, selections, teams WHERE privateleague.privateleaguename = '$league_name' AND privateleague.privateleagueid = user_leagues.privateleagueid AND user_leagues.userid = login.userid AND login.userid = selections.userid AND selections.groups = teams.groups GROUP by login.userid ORDER by SUM(teams.points) DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?> <tr class="teams"> <td width="50">'team position here'</td> <td width="250"><?php echo $row['forename']; ?> <?php echo $row['surname']; ?></td> <td width="250"><?php echo $row['teamname']; ?></td> <td width="50"><?php echo $row['SUM(teams.points)']; ?></td> </tr> <?php } ?> </table> Link to comment https://forums.phpfreaks.com/topic/242184-table-position-help/ Share on other sites More sharing options...
cssfreakie Posted July 17, 2011 Share Posted July 17, 2011 if you know the column-name of the 'position' (not sure what you mean with a generic description as position though) it's pretty much the same as the other variables your outputting in the while loop.so have a look at your tables ones you know the name of the column fetch it just like you did with the other variables. So make sure your selecting that value in your query. <table width="350" border="0" cellpadding="0" cellspacing="0" class="myteams"> <tr class="title"> <td width="50">Position</td> <td width="250">Name</td> <td width="250">Team Name</td> <td width="50">Points</td> </tr> <?php $query = "SELECT privateleague.privateleagueid, privateleague.privateleaguename, user_leagues.privateleagueid, user_leagues.userid, login.userid, login.forename, login.surname, login.teamname, selections.userid, SUM(teams.points) FROM privateleague, user_leagues, login, selections, teams WHERE privateleague.privateleaguename = '$league_name' AND privateleague.privateleagueid = user_leagues.privateleagueid AND user_leagues.userid = login.userid AND login.userid = selections.userid AND selections.groups = teams.groups GROUP by login.userid ORDER by SUM(teams.points) DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?> <tr class="teams"> <td width="50"><?php echo $row['position']; ?></td> <td width="250"><?php echo $row['forename']; ?> <?php echo $row['surname']; ?></td> <td width="250"><?php echo $row['teamname']; ?></td> <td width="50"><?php echo $row['SUM(teams.points)']; ?></td> </tr> <?php } ?> </table> Link to comment https://forums.phpfreaks.com/topic/242184-table-position-help/#findComment-1243700 Share on other sites More sharing options...
lukep11a Posted July 17, 2011 Author Share Posted July 17, 2011 But the position isn't stored within the mysql tables, shouldn't it be generated automatically depending on which teams have the most points? Or am I mis-understanding what you're saying? Link to comment https://forums.phpfreaks.com/topic/242184-table-position-help/#findComment-1243701 Share on other sites More sharing options...
cssfreakie Posted July 17, 2011 Share Posted July 17, 2011 Could you give a definition of what you mean with position? i can think of at least 4 things it could mean when it comes to sport. Could you maybe also give an example. like 3 rows of how you want it to look so we can have a better understanding of what you mean with position. Make it as practical as possible. or do you maybe mean The rank, as in the first row is first place second row is second place et cetera? if that is the case do the following: <?php $counter = 1; // set a counter value while($row = mysql_fetch_assoc($result)) { ?> <tr class="teams"> <td width="50"><?php echo $counter; //output the counter ?></td> <td width="250"><?php echo $row['forename']; ?> <?php echo $row['surname']; ?></td> <td width="250"><?php echo $row['teamname']; ?></td> <td width="50"><?php echo $row['SUM(teams.points)']; ?></td> </tr> <?php $counter++; //increase the value of the counter with 1 } ?> Link to comment https://forums.phpfreaks.com/topic/242184-table-position-help/#findComment-1243702 Share on other sites More sharing options...
harlequeen Posted July 17, 2011 Share Posted July 17, 2011 If I'm understanding you correctly, you want the position of the person in the table? So if they are first, it shoudl say 1. If that is the case I think you can count the rows in the table which is generated by your query and then output the variable($size in the example below) in the cell, as you are doing for the other variables. $size=count($_GET['position']); Hope this is what you mean. Harlequeen Link to comment https://forums.phpfreaks.com/topic/242184-table-position-help/#findComment-1243703 Share on other sites More sharing options...
cssfreakie Posted July 17, 2011 Share Posted July 17, 2011 If I'm understanding you correctly, you want the position of the person in the table? So if they are first, it shoudl say 1. If that is the case I think you can count the rows in the table which is generated by your query and then output the variable($size in the example below) in the cell, as you are doing for the other variables. $size=count($_GET['position']); Hope this is what you mean. Harlequeen and what has a $_GET variable to do with that..? Link to comment https://forums.phpfreaks.com/topic/242184-table-position-help/#findComment-1243705 Share on other sites More sharing options...
lukep11a Posted July 17, 2011 Author Share Posted July 17, 2011 Sorry for not explaining 'position' properly, it was the rank I was refering to though, and that code works perfectly, thankyou Link to comment https://forums.phpfreaks.com/topic/242184-table-position-help/#findComment-1243734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.