Jump to content

Table position help?


lukep11a

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.