Jump to content

Archived

This topic is now archived and is closed to further replies.

mAdMaCCa

CASE statement with Stock Level not working! *solved*

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

Share this post


Link to post
Share on other sites
Just the way the script works...it doesn;t display the stock level at all if the price is zero. Any price over zero and it displays!

Share this post


Link to post
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

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

×

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.