-
generate variable
Every time the winning team wins I would like to have this image appear after the winning team name. Now to determine the winning team is based on the highest runs.
Take a look at this page to understand what I mean. Now please don't be fooled by is appearing after the winning team because the command isn't correct. It just appears on the bottom team or the home team.
away = top team
bottom = home.
Here is the PHP code
PHP Code:
<?php
$generate = '';
$result = mysql_query("SELECT * FROM boxscoreaway ORDER BY 'id' ASC");
$away = mysql_fetch_array($result);
$result = mysql_query("SELECT * FROM boxscorehome ORDER BY 'id' ASC");
$home = mysql_fetch_array($result);
// the away team just began
$generate .= '<tr style="background-color:eeeeee">
<td width="254"><table width="100%" border="0">
<tr>
<td id="team" width="40%">' . $away['team'] . '</td>
<td align="left" width="60%">';
if( $away['winner'] != '' ) {
$generate .= '<img src="http://robbyzworld.com/personal/images/sports/nyy/winner.gif" />';
}
$generate .= '</td>
</tr>
</table></td>
<td width="30" id="RHE">' . $away['R'] . '</td>
<td width="30" id="RHE">' . $away['H'] . '</td>
<td width="30" id="RHE">' . $away['E'] . '</td>
</tr>';
// the away team just ended
// the home team just began
$generate .= '<tr style="background-color:eeeeee">
<td width="254"><table width="100%" border="0">
<tr>
<td id="team" width="40%">' . $home['team'] . '</td>
<td align="left" width="60%">';
if( $home['winner'] != '' ) {
$generate .= '<img src="http://robbyzworld.com/personal/images/sports/nyy/winner.gif" />';
}
$generate .= '</td>
</tr>
</table></td>
<td width="30" id="RHE">' . $home['R'] . '</td>
<td width="30" id="RHE">' . $home['H'] . '</td>
<td width="30" id="RHE">' . $home['E'] . '</td>
</tr>';
// end the home team just ended
echo $generate;
?>
-
Re: generate variable
just check if the away runs is higher than the home runs. if so, then the away team wins. otherwise, the home team wins.
PHP Code:
if($away['R'] > $home['R']){
$winner = "away";
}elseif($away['R'] == $home['R']){
$winner = "tie";
}else{
$winner = "home";
}
-
Re: generate variable
where do I put that code though?
-
Re: generate variable
just after your SQL queries, and before you're starting to output anything.. then, instead of checking if $away['winner'] is not equal to a null string, you just have to check if $winner is equal to "away"; then you need to change the same for the "home" part as well.
-
Re: generate variable
Style point: you should never put HTML in strings. PHP is not Perl, it is an embedded scripting language. Just close the PHP block: ?>
For anything non-trivial, you should really be using some sort of template system.
-
Re: generate variable
Thanks Kows!
Penagate, what do you mean by html strings?
-
Re: generate variable
-
Re: generate variable
why is echoing a whole chunk not a good thing?
If you add an echo on each line isn't it more code?
-
Re: generate variable
it can be confusing and sloppy to use echo to output HTML. PHP is an embedded language; that means you embed into HTML -- not use it to output HTML. if it can be avoided, it should be. it makes your code twenty-million times easier to read (yes, really, that many times). it's probably faster (though, admittedly, probably not that much faster) this way, too.
-
Re: generate variable
ahh ok....
I am still earning so once I conquer that then I will take the next step and try to make it so my coding is more proficient and easier to read.
Thanks for the tips!