pein87's Avatar
Ambitious contributor
Ok let me ask you this, what do you want the program to do? What is the end result, once you tell me I can help you rewrite this code so it works how you want it to work.Will get you two include pages config.php and functions.php and then get this code to work properly.
newphpcoder's Avatar, Join Date: Sep 2010
Ambitious contributor
I want that the program to do is if the cloth type is AAA or BBB or CCC the if statement work which has a formula and if the cloth type is not mention like DDD the else statement which also a different formula. Now the if condition only works even the cloth type is DDD. I already include the config.php but i don't have functions.php

Thank you
pein87's Avatar
Ambitious contributor
Ok simple compare the value of what ever is being used as the cloth type source. If your using data retrieved from a database table wrap the if statement in there so that it does it for each instance of the data or else just us a plan old if statement. The functions.php is so you can add most of your logic in functions so you dont have to recode everything every time you want to use it. Lets do a hypothetical situation.

General if statement checking if value is one or the other. You need to specify each time what variable and value pairs are being evaluated. I noticed you used if($clothType == "AAA" || "BBB" || "CCC") which explains why its not working. It would be nice if it did work that way but it does not see below how it should be done.
PHP Code:
<?php

$clothType 
$_POST['cloth_type'];

if(
$clothType == "AAA" || $clothType == "BBB" || $clothType == "CCC")
{

// code to execute

}
else
{
//value is not one for the three do another calculation here

}

?>

You can make a function for calculating the total cost easy

PHP Code:
<?php

function calculateCost($itemAmt,$Cost,$Tax,$preTax="false",$round="true")
{

//make sure the values are numeric
if(!is_numeric($itemAmt) && !is_numeric($Cost) && !is_numeric($Tax))
{
// all items need to be numeric of else this will not work
return "NaN";

}
else
{
// everything is a number lets roll
$subTotal $itemAmt $Cost;

$totalAmt $subTotal $Tax;

if(
$preTax == "true")
{

return 
$subTotal;
}
else
{

if(
$round == "true")
{

return 
round($totalAmt);

}
else
{

return 
$totalAmt;

}
}
}

?>
This function will make doing total calculations simple just call the function and fill in the params. I think I already posted a percentage function but yeah anything that is not fixed you should turn into a function to save coding time and file bloat.
underground_devil's Avatar, Join Date: Jan 2011
Go4Expert Member
in PHP or many other language
if condition run on boolen expression ...
like if the condition or result would be true or 1 then your inner condition will be run
else if it return 0 or false then the condtion would not be satisfy

like in php
when we check if($_POST['abc'])
this will check is any value of $_POST['abc'] if it occure either null it could be run else it will return false