Sunday, 29 September 2013

If total is between two numbers echo statement, else if between different set of numbers echo a different statement, etc

If total is between two numbers echo statement, else if between different
set of numbers echo a different statement, etc

I am terrible with figuring out if/else statements. I have looked at
multiple tutorials and just can't get what I'm trying to do work. I need
this: If total amount of points is less than # state that no title is
achieved If total amount is between # and # state what title that would be
If total amount is between higher # and # state what title that would be
etc.
The adding of total points works just fine but I can't figure out how to
get the correct title for the total points to show. I have included the
code for getting totalpoints as well in case it can be combined with what
I am trying to do. Any help greatly appreciated
This works just fine:
<?php
$query = "SELECT points, SUM(points) AS totalpoints FROM competition WHERE
id = $id";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "<b>";
echo $row['totalpoints'];
echo "pts</b>";
}?>
This does not work:
<?php
$query = "SELECT points, SUM(points) AS totalpoints FROM competition WHERE
id = $id";
$result = mysql_query($query) or die(mysql_error());
while($titled = mysql_fetch_array($result)) {
if ($titled <= 999)
{echo ", not titled";}
elseif (($titled == 1000) && ($titled <= 1999))
{$titlename = ", Champion";}
elseif (($titled >= 2000) && ($titled <= 2999))
{$titlename = ", Grand Champion";}
elseif (($titled >= 3000) && ($titled <= 3999))
{$titlename = ", Honor Champion";}
elseif (($titled >= 4000) && ($titled <= 5999))
{$titlename = ", Regional Champion";}
elseif (($titled >= 6000) && ($titled <= 7999))
{$titlename = ", State Champion";}
elseif (($titled >= 8000) && ($titled <= 9999))
{$titlename = ", National Champion";}
elseif (($titled >= 10000) && ($titled <= 19999))
{$titlename = ", World Champion";}
elseif ($titled >= 20000)
{$titlename = ", Hall of Fame";}
}?>

No comments:

Post a Comment