• Notice regarding image hosts and attachments. See here.

Setting Variable Parameter with IF PHP

Associate
Joined
2 Jan 2007
Posts
427
Location
Epsom, Surrey
Hey all,

just wondering if its possible to set a variable using an IF Statement:



$baseprice = 15;

if ($_POST['slots']=="10"){
$slotsum = 0;
} elseif ($_POST['slots']=="12"){
$slotsum = 1;
} elseif ($_POST['slots']=="14"){
$slotsum = 2;
} elseif ($_POST['slots']=="16"){
$slotsum = 3;
} elseif ($_POST['slots']=="18"){
$slotsum = 4;
} elseif ($_POST['slots']=="20"){
$slotsum = 5;
} elseif ($_POST['slots']=="22"){
$slotsum = 6;
} elseif ($_POST['slots']=="24"){
$slotsum = 7;
} elseif ($_POST['slots']=="26"){
$slotsum = 8;
} elseif ($_POST['slots']=="28"){
$slotsum = 9;
} elseif ($_POST['slots']=="30"){
$slotsum = 10;
}else {
$slotsum = 11;
}


$total=$baseprice + $slotsum;



Could this work?

Thanks
 
Yeah, i have tested it but im only getting it read out 15.

Its not adding the slotsum variable.


Ive changed it slightly to:

$baseprice = 15;


function slotSum(){

if ($gameslots=="10"){
$slotsum = 0;
} elseif ($gameslots=="12"){
$slotsum = 1;
} elseif ($gameslots=="14"){
$slotsum = 2;
} elseif ($gameslots=="16"){
$slotsum = 3;
} elseif ($gameslots=="18"){
$slotsum = 4;
} elseif ($gameslots=="20"){
$slotsum = 5;
} elseif ($gameslots=="22"){
$slotsum = 6;
} elseif ($gameslots=="24"){
$slotsum = 7;
} elseif ($gameslots=="26"){
$slotsum = 8;
} elseif ($gameslots=="28"){
$slotsum = 9;
} elseif ($gameslots=="30"){
$slotsum = 10;
}else {
$slotsum = 11;
}

}



$total=$baseprice + slotSum();;



Still only getting the $baseprice.
 
Back
Top Bottom