Jump to content


Photo

CASE statement with Stock Level not working! *solved*


  • Please log in to reply
6 replies to this topic

#1 mAdMaCCa

mAdMaCCa
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 October 2006 - 08:41 PM

:-[
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???

  <?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;
     }     
  ?>

The result, as I guess most of your are aware, is always "Last Few Remaining!"

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

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 27 October 2006 - 08:45 PM

Why does the stock level depend on the price?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 mAdMaCCa

mAdMaCCa
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 October 2006 - 08:49 PM

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!

#4 mAdMaCCa

mAdMaCCa
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 October 2006 - 08:52 PM

Aaaaah, see wot U mean...wot a muppet! I'll have a play, thanx!

#5 mAdMaCCa

mAdMaCCa
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 October 2006 - 08:58 PM

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

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 27 October 2006 - 09:08 PM

if I use this code and manually set the value on the first line then it works fine
<?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;
?>

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

echo $product_info['products_price']; (or whatever the correct field is now)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 mAdMaCCa

mAdMaCCa
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 October 2006 - 09:37 PM

All Sorted!  ;D

Thanx for all your help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users