Jump to content

[SOLVED] IF statment inside an IF statment ?


crazzypappy

Recommended Posts

Ok heres what i want to do

 

i have a race script and would like to work out the chances of beating each person car speed vs car speed , the script give mph for both users

 

i have worked out how to show a percentage but sometimes its showing 200 % so i want to do is create an if - elseif to limit the percentage shown as 100%

 

this is what i have got so far but it is giving me errors

 

else {
if ( $_GET['race'] ) {
  $racer = $_GET['race'];


  if ( $racer == 'chris' ) {
$fuel      = rand(5,12);

   $raced  = "Chris";

   $speeds = "20";

   $ra     = "1";
   
   $percent = mph/$speeds*100;
   
   $Percent2 = $percent;
   
   $nextrace = time()+120;

   $reps      = rand(500,1200);

   $mns       = rand(200,1500);

//this is the section im having trouble with

   $percent3 = (if ($percent >= 100){
			echo "100" }
			elseif ($percent < 100){
			echo $Percent2})

   }


  elseif ( $racer == 'jon' ) {

 

 

Thanks for any help you can offer

 

im confused why you have an if inside a variable. should'nt need to be.

 

try

<?php
if ($percent >= 100) {
    echo "100";
  } 
  else if ($percent < 100) {
    echo $Percent2;
  }
?>

 

or (not sure what your trying to accomplish but...

 

<?php
if ($percent >= 100) {
    $percent3 = 100;
  } 
  else if ($percent < 100) {
    $percent3 = $Percent2;
  }
?>

 

no the mph comes from a sql table

 

the original script that does give a result is

 

if ( $racer == 'chris' ) {
$fuel      = rand(5,12);

   $raced  = "Chris";

   $speeds = "20";

   $ra     = "1";
   
   $percent = mph/$speeds*100;
   
   $nextrace = time()+120;

   $reps      = rand(500,1200);

   $mns       = rand(200,1500);

   
   }

 

 

but what happens is if mph is like 300 it would give me a result larger than 100 % and i want to limit the ansver no greater than 100 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.