cowboysdude Posted December 23, 2015 Share Posted December 23, 2015 (edited) I'm working on this module and so far so good BUT I would like to be able to highlight the higher score and for some reason I'm having an issue with it... It's more of an else statement issue... Here is what I have.... if ($game['q'] == 'P') { ?> <li><div class=box-blue> <?= $game['d'] ?> | <?= $datey ?> | <?= $game['t'] ?></div> <?= $homeTeam ?> <?= $game['hs'] ?> <br /> <?= $visitingTeam ?> <?= $game['vs'] ?> <br /> <div class=box-blue> Game Temp: <?= $current ?>° Condition: <?= $condition ?> </div></li> <?php } else { ?> <li><?= $homeTeam ?> <?= $game['hs'] ?> <br /><?= $visitingTeam ?> <?= $game['vs'] ?> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } ?> <?php if ($game['q'] == "FO") {?>Final Overtime<?php }?> <?php if ($game['q'] == "H") {?>Half Time<?php }?> <?php if ($game['q'] == "1") {?>1st Quarter<?php } ?> <?php if ($game['q'] == "2") {?>2nd Quarter<?php } ?> <?php if ($game['q'] == "3") {?>3rd Quarter<?php } ?> <?php if ($game['q'] == "4") {?>4th Quarter<?php } ?> <?php if ($game['q'] == "T") {?>Tie<?php }?> <?= $game['k'] ?> </div></li> <?php } What I tried to add was this.. If( $game['hs'] > $game['vs'] ){ ?> <li><?= $homeTeam ?> <font color=red><?= $game['hs'] ?></font> <br /><?= $visitingTeam ?> <?= $game['vs'] ?> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } else {?> <li><?= $homeTeam ?> <?= $game['hs'] ?> <br /><?= $visitingTeam ?> <font color=red><?= $game['vs'] ?></font> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } But when I do I get an else error... what am I missing here? I thought this would be pretty easy... Thank yoU! Edited December 23, 2015 by cowboysdude Quote Link to comment Share on other sites More sharing options...
benanamen Posted December 23, 2015 Share Posted December 23, 2015 (edited) I am not even going to touch this except to say that the font tag is deprecated. You need to use the span tag for an inline style. You have about 50% more code than what you need. Edited December 23, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
benanamen Posted December 23, 2015 Share Posted December 23, 2015 Okay, I guess I am touching this.. Here is a start $game['q']='FO'; $g= $game['q']; $status = array('FO' =>'Final Overtime', 'H'=>'Half Time', 1=>'1st Quarter', 2=>'2nd Quarter', 3=>'3rd Quarter', 4=>'4th Quarter', 'T'=>'Tie'); echo $status[$g]; Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted December 23, 2015 Share Posted December 23, 2015 What I tried to add was this.. If( $game['hs'] > $game['vs'] ){ ?> <li><?= $homeTeam ?> <font color=red><?= $game['hs'] ?></font> <br /><?= $visitingTeam ?> <?= $game['vs'] ?> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } else {?> <li><?= $homeTeam ?> <?= $game['hs'] ?> <br /><?= $visitingTeam ?> <font color=red><?= $game['vs'] ?></font> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } But when I do I get an else error... what am I missing here? You're missing an open curly bracket before the else. And the else needs to be closed with a curly bracket. You could try something like this: if( $game['hs'] > $game['vs'] ){ ?><li><?= $homeTeam ?> <font color=red><?= $game['hs'] ?></font> <br /><?= $visitingTeam ?> <?= $game['vs'] ?> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } } else { ?><li><?= $homeTeam ?> <?= $game['hs'] ?> <br /><?= $visitingTeam ?> <font color=red><?= $game['vs'] ?></font> <br /> <div class=box-blue> <?php if ($game['q'] == "F") {?>Final<?php } } Quote Link to comment Share on other sites More sharing options...
benanamen Posted December 23, 2015 Share Posted December 23, 2015 (edited) That is still a mess of duplicate code. DRY: Don't Repeat Yourself. * Still could be improved. <?php if ($game['hs'] > $game['vs']) { $home_color = '<span style="color:red">'; $visitor_color = '<span>'; } else { $home_color = '<span>'; $visitor_color = '<span style="color:red">'; } ?> <li> <?php echo "$homeTeam $home_color {$game['hs']} </span> <br> $visitingTeam $visitor_color {$game['vs']} </span>";?> <br> <div class=box-blue> </div> </li> <?php if ($game['q'] == "F") { echo 'Final'; }?> Edited December 23, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.