View Single Post
Old 12-04-2012, 04:49 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No, there's no limit to the number of elseif statements beyond memory usage. Which is a lot.
The problem is this: if($Add_on1 = "plain only-$0.95"):, these are assignments, not comparisons. To compare use == or the strcmp function. As soon as you assign, it automatically is successful so only the first ever triggers and $Add_on1 is assigned this value.
Using if/else with this many though would probably be easier to use a switch statement:
PHP Code:
switch ($Add_on1)
{
    case 
'plain only-$0.95':
        print 
0.95;
        break;
    
//...
    
case 'Chicken with egg & cheese - $2.50':
        print 
2.5;
        break;

And so forth.
Depending on overall rules, you can use explode to break the text from the dollar amount by using the hyphen as the delimiter.
PHP Code:
$aParts explode('-'$Add_on1);
$sDescription trim($aParts[0]);
$dPrice trim($aParts[1], ' $'); 
Now you can pick the description and price out of the $Add_on1 without needing to if/elseif or switch them.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
sweetpeet (12-05-2012)