Jump to content

[SOLVED] Need Help With This One


refiking

Recommended Posts

I am trying to echo all of the winners from the db.  How can I show all of them.  Right now, it only shows the last entry in the table.  Here is my code as is:

 


include 'header.php';
include 'cont.php';
$sql = mysql_query("SELECT * FROM scores");
while ($row = mysql_fetch_assoc($sql)) {
$hscore = $row['homescore'];
$ascore = $row['awayscore'];
$home = $row['home'];
$away = $row['away'];
$timestamp = $row['timestamp'];
$round = $row['roundname']; 
}
IF ($hscore >= $ascore) {
$winner = $home;
}
IF ($ascore >= $hscore) {
$winner = $away;
}
Echo $winner;

Link to comment
Share on other sites

Try

 

<?php

include 'header.php';
include 'cont.php';

$sql = mysql_query("SELECT * FROM scores");

while ($row = mysql_fetch_assoc($sql)) {

   $hscore = $row['homescore'];
   $ascore = $row['awayscore'];
   $home = $row['home'];
   $away = $row['away'];
   $timestamp = $row['timestamp'];
   $round = $row['roundname'];
    
   if ($hscore >= $ascore) {
       $winner = $home;
   }
   if ($ascore >= $hscore) {
       $winner = $away;
   }

   echo $winner.'<br>';

}

?>

Link to comment
Share on other sites

Well, then there is only one record in the table. Run this code, and copy/paste the output.

 

<?php
  include 'header.php';
  include 'cont.php';

  $sql = mysql_query("SELECT * FROM scores");
  print "Row Count: ".mysql_num_rows($sql)."<br>";

  while ($row = mysql_fetch_assoc($sql)) {
    $hscore = $row['homescore'];
    $ascore = $row['awayscore'];
    $home = $row['home'];
    $away = $row['away'];
    $timestamp = $row['timestamp'];
    $round = $row['roundname'];
    
    if($hscore > $ascore){
      $winner = $home;
    }elseif($ascore > $hscore){
      $winner = $away;
    }else{
      $winner = "TIE";
    }
    echo "Winner: $winner<br>";
  }
?>

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.