refiking Posted January 25, 2008 Share Posted January 25, 2008 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 https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/ Share on other sites More sharing options...
pocobueno1388 Posted January 25, 2008 Share Posted January 25, 2008 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 https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449094 Share on other sites More sharing options...
refiking Posted January 25, 2008 Author Share Posted January 25, 2008 No dice. Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449106 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 So the new code produces the same output? Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449107 Share on other sites More sharing options...
refiking Posted January 25, 2008 Author Share Posted January 25, 2008 yes. It only shows the last record in the table Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449111 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 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 https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449115 Share on other sites More sharing options...
refiking Posted January 25, 2008 Author Share Posted January 25, 2008 That worked. Here is the output: Row Count: 5 Winner: HittFaktory Winner: bidness Winner: win Winner: bidness Winner: win Now, how can I store these into another db table? Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449117 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 Have you created the table yet? Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449120 Share on other sites More sharing options...
refiking Posted January 25, 2008 Author Share Posted January 25, 2008 yes, it's based on a tournament. The table it needs to go to is 'tourney'. It's based on a tid(tournament id), which is also retrieved from the same table (scores) where I queried the scores in the script. Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449126 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 Can you try and describe in more detail what you are looking to do with the script? Like so: Every time the script runs, I want to ..... Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449142 Share on other sites More sharing options...
refiking Posted January 25, 2008 Author Share Posted January 25, 2008 Here's what I have so far: mysql_query("INSERT into tourney (tid, home,away,homescore,awayscore,winner) VALUES ('$tid','$home','$away','$hscore','$ascore','$winner')"); Right now, it only inputs the last record. Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449196 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 Did you put it inside the loop? Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449206 Share on other sites More sharing options...
refiking Posted January 25, 2008 Author Share Posted January 25, 2008 That's what it was. It was outside of the loop. Link to comment https://forums.phpfreaks.com/topic/87799-solved-need-help-with-this-one/#findComment-449216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.