Jump to content

CASE statement with Stock Level not working! *solved*


mAdMaCCa

Recommended Posts

:-[
Hi, i'm a noob to php and have a sort of OSCommerce version of an ecommerce site. I want to be able to replace the current displayed stock level with a text description based on how much stock there is. I've spent hours here and on various other php sites trying to find the answer, and thought I had...however, regardless of the stock level it always displays the same result!
Anyway, here is the CASE code I have worked out and I can't seem to see what is wrong with it...can anyone help please???

[code]
  <?php
  $txtQuantity = "";
    switch (true){
    case $product_info['products_price'] <= 0:
    $txtQuantity = "More In Soon";
    break;
    case $product_info['products_price'] <= 10:
    $txtQuantity = "Last Few Remaining!";
    break;
    case $product_info['products_price'] > 10:
    $txtQuantity = "Yes";
    break;
    }   
  ?>
[/code]

The result, as I guess most of your are aware, is always [color=red]"Last Few Remaining!"[/color]

The line that follows is: [code]<td class="boxtext" align="center"><?php echo '' . (($product_info['products_price'] > 0) ?  '' . TEXT_QUANTITYSTOCK . ' '  . $txtQuantity  : ''); ?></td>[/code]

but i've only put it here so you can see how I display it, i'm pretty sure it's got nothing to do with it not working  ???

Please HELP!!!

Thanks in advance,
mAdMaCCa
Link to comment
Share on other sites

Obviously U were right, I was testing the wrong field, however, it still doesn't work...

The result has changed though...now it's always "Yes" regardless of how much stock there is n :P

Any chance you can point me in the right direction???

Cheers

mAdMaCCa
Link to comment
Share on other sites

if I use this code and manually set the value on the first line then it works fine
[code]
<?php
    $product_info['products_price'] = 25;  // <-- change this value and run it
    $txtQuantity = "";
    switch (true){
    case $product_info['products_price'] <= 0:
    $txtQuantity = "More In Soon";
    break;
    case $product_info['products_price'] <= 10:
    $txtQuantity = "Last Few Remaining!";
    break;
    case $product_info['products_price'] > 10:
    $txtQuantity = "Yes";
    break;
    }   
    echo $txtQuantity;
?>
[/code]

So it must be something to do with your value, try adding

echo $product_info['products_price']; (or whatever the correct field is now)
Link to comment
Share on other sites

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.