Jump to content

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 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.