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
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Jul 16, 2004 1:32 am
Code: Select all
<?php
<?php
if (!defined("IN_SITE"))
{
exit("Hacking Attempt!");
}
$result = mysql_query("SELECT * FROM `matches`") or die("[matches.php] Select Error ". mysql_error());
while ($row = mysql_fetch_array($result))
{
$x = 0;
$round1 = explode("-",$row["round1"]);
$round2 = explode("-",$row["round2"]);
for($x = 0; $x < 2; $x++)
{
switch ($round1[$x]) :
case $round1[$x] > $round1[$x+1] :
$round1[$x] = "<font color='#666666'>".$round1[$x]."-".$round1[$x+1]."</font>";
break;
case $round1[$x] < $round1[$x+1] :
$round1[$x] = "<font color='#999999'>".$round1[$x]."-".$round1[$x+1]."</font>";
break;
endswitch;
switch ($round2[$x]) :
case $round2[$x] > $round2[$x+1] :
$round2[$x] = "<font color='#666666'>".$round2[$x]."-".$round2[$x+1]."</font>";
break;
case $round2[$x] < $round2[$x+1] :
$round2[$x] = "<font color='#999999'>".$round2[$x]."-".$round2[$x+1]."</font>";
break;
endswitch;
}
// will output all the info here as it loops through each row
}
?>
?>
This took me like an hour of thinking to get the logic of this... but it looks ugly !! Does anyone have an idea to minimize the lines?
btw this is my first time using switch statement...
BRAVO FOR ME!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 1:51 am
This assumes you want to do "something" with ties..
Code: Select all
<?php
if (!defined("IN_SITE")) { exit("Hacking Attempt!"); }
$result = mysql_query("SELECT * FROM `matches`") or die("[matches.php] Select Error ". mysql_error());
while ($row = mysql_fetch_assoc($result))
{
$round1 = explode("-",$row["round1"]);
$round2 = explode("-",$row["round2"]);
for($x = 0; $x < 2; $x++)
{
$round1[$x] = '<font'.($round1[$x] > $round1[$x+1] ? ' color="#666666"' : ($round1[$x] != $round1[$x+1] ? ' color="#999999"' : '' ) ).'>'.$round1[$x]."-".$round1[$x+1]."</font>";
$round2[$x] = '<font'.($round2[$x] > $round2[$x+1] ? ' color="#666666"' : ($round2[$x] != $round2[$x+1] ? ' color="#999999"' : '' ) ).'>'.$round2[$x]."-".$round2[$x+1]."</font>";
}
// will output all the info here as it loops through each row
}
?>
Last edited by
feyd on Fri Jul 16, 2004 1:59 am, edited 1 time in total.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Jul 16, 2004 1:54 am
unexpected : on line 54
Code: Select all
<?php
$round1[$x] = '<font'.($round1[$x] > $round1[$x+1] ? ' color="#666666"'. : ($round1[$x] != $round1[$x+1] ? ' color="#999999"' : '' ) ).'>'.$round1[$x]."-".$round1[$x+1]."</font>";
?> is line 54
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 16, 2004 1:59 am
oops. had an extra dot in there.. try it now.