Page 1 of 1

Baseketball teams ladder help (DESC)

Posted: Tue Mar 01, 2011 9:00 pm
by DFORMS
Hi,

I need help finishing this ladder for my school's basketball teams. Everything works fine but I want to show the teams with the most points on top of the ladder (DESC). Would it be possible the get some help? I have tried a few things but I am unable to figure this one out. Here is my page :

Code: Select all

<?php
$liaison = mysql_connect ("#", "#", "#");
mysql_select_db("#");
$sql = "select * from #";

if (isset($_REQUEST["ordre"])) {
  $sql .= " order by ".mysql_real_escape_string($_REQUEST["ordre"]) ;
  }

$user = mysql_query($sql);


?>

<html>
<head>
  <title>School Teams 2010-2011</title>

<style type="text/css">
#a {
position: absolute;
top: 0px;
left:0px;
z-index: 2;
}

td.user_info { border: 1px; border-color: #FFF; 
border-style: solid; }


</style>
  
</head>
<body>
<div id="a">
<table border="0" width="875px" cellspacing="0">
  <tr>
   <td class="user_info" bgcolor="#65a7ce"><span style="color: #FFF; padding-left: 5px"><strong>Player</strong></span></td>
   <td class="user_info" bgcolor="#65a7ce"><span style="color: #FFF; padding-left: 5px"><strong>Courriel</strong></span></td>
   <td class="user_info" bgcolor="#65a7ce"><span style="color: #FFF; padding-left: 5px"><strong>W</strong></span></td>
   <td class="user_info" bgcolor="#65a7ce"><span style="color: #FFF; padding-left: 5px"><strong>L</strong></span></td>
   <td class="user_info" bgcolor="#65a7ce"><span style="color: #FFF; padding-left: 5px"><strong>Pts</strong></span></td>
  <?php while (($ladder_1v1 = mysql_fetch_assoc ($user))
  !== false): ?>
  <tr>
    <td class="user_info" bgcolor="#dcebfe" style="padding:5px">
    <?php echo $ladder_1v1["user"]; ?>
      <!-- mod // -->     
      <a href="modifier.php?id=<?php echo $ladder_1v1["id"]; ?>">
      [Modifier]</a>&nbsp;
      <!-- mod // -->
      
      <!-- delete // -->
      <a href="supprime.php?id=<?php echo $ladder_1v1["id"]; ?>">
      [Suprimer]</a>
      <!-- delete // -->
    </td>
      
    <td class="user_info" bgcolor="#dcebfe" style="padding:5px">
      <?php echo $ladder_1v1["email"]; ?>
    </td>
    
    <td class="user_info" bgcolor="#dcebfe" style="padding:5px">
      <?php 
      echo $ladder_1v1["win"]; 
      ?>
    </td>
    
    <td class="user_info" bgcolor="#dcebfe" style="padding:5px">
      <?php 
      echo $ladder_1v1["loss"]; 
      ?>
    </td>
    <td class="user_info" bgcolor="#dcebfe" style="padding:5px">
      <?php 
       $pts = ($ladder_1v1["win"] * 5 ) - ($ladder_1v1["loss"] * 5); 
       
       echo $pts;
      ?>
    </td>
  </tr>
  <?php endwhile ?>
</table>
 </div>   
</body>
</html>
<?php
mysql_close($liaison);
?>
Thank you!

Re: Baseketball teams ladder help (DESC)

Posted: Tue Mar 01, 2011 10:16 pm
by Jonah Bron
What is the name of the column that holds their points?

Re: Baseketball teams ladder help (DESC)

Posted: Tue Mar 01, 2011 10:50 pm
by jim.barrett
It seems to me that the most straightforward way may be to add a 'pts' field to the db (with the calculations performed when wins/losses are uploaded), and it would be a simple matter of " ORDER BY pts DESC"?

Re: Baseketball teams ladder help (DESC)

Posted: Wed Mar 02, 2011 10:31 am
by DFORMS
Thank you for the replies guys! The name of the 'individual players stats' columns are:

id - user - email - win - loss;

no 'pts' column. I don't know how to add a column = (win * 5) - (loss * 5) with the columns 'win' and 'loss' within my database : s How would I go about creating the 'pts' column?

Re: Baseketball teams ladder help (DESC)

Posted: Wed Mar 02, 2011 7:15 pm
by DFORMS
up, anyone?

Re: Baseketball teams ladder help (DESC)

Posted: Thu Mar 03, 2011 4:04 pm
by Jonah Bron
Not tested, but this query should work.

Code: Select all

SELECT id, user, email, win, loss, ((win*5)-(loss*5)) AS points FROM mytable ORDER BY points DESC

Re: Baseketball teams ladder help (DESC)

Posted: Wed Mar 09, 2011 1:33 pm
by DFORMS
Jonah Bron you are the man! It's working, dude thank you sooo much!

Re: Baseketball teams ladder help (DESC)

Posted: Wed Mar 09, 2011 8:29 pm
by Jonah Bron
Glad I could help :)