Baseketball teams ladder help (DESC)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DFORMS
Forum Newbie
Posts: 4
Joined: Tue Mar 01, 2011 8:46 pm

Baseketball teams ladder help (DESC)

Post 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!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Baseketball teams ladder help (DESC)

Post by Jonah Bron »

What is the name of the column that holds their points?
jim.barrett
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2011 5:47 am

Re: Baseketball teams ladder help (DESC)

Post 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"?
DFORMS
Forum Newbie
Posts: 4
Joined: Tue Mar 01, 2011 8:46 pm

Re: Baseketball teams ladder help (DESC)

Post 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?
DFORMS
Forum Newbie
Posts: 4
Joined: Tue Mar 01, 2011 8:46 pm

Re: Baseketball teams ladder help (DESC)

Post by DFORMS »

up, anyone?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Baseketball teams ladder help (DESC)

Post 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
DFORMS
Forum Newbie
Posts: 4
Joined: Tue Mar 01, 2011 8:46 pm

Re: Baseketball teams ladder help (DESC)

Post by DFORMS »

Jonah Bron you are the man! It's working, dude thank you sooo much!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Baseketball teams ladder help (DESC)

Post by Jonah Bron »

Glad I could help :)
Post Reply