mAdMaCCa Posted October 27, 2006 Share Posted October 27, 2006 :-[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 https://forums.phpfreaks.com/topic/25349-case-statement-with-stock-level-not-working-solved/ Share on other sites More sharing options...
Barand Posted October 27, 2006 Share Posted October 27, 2006 Why does the stock level depend on the price? Link to comment https://forums.phpfreaks.com/topic/25349-case-statement-with-stock-level-not-working-solved/#findComment-115568 Share on other sites More sharing options...
mAdMaCCa Posted October 27, 2006 Author Share Posted October 27, 2006 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! Link to comment https://forums.phpfreaks.com/topic/25349-case-statement-with-stock-level-not-working-solved/#findComment-115570 Share on other sites More sharing options...
mAdMaCCa Posted October 27, 2006 Author Share Posted October 27, 2006 Aaaaah, see wot U mean...wot a muppet! I'll have a play, thanx! Link to comment https://forums.phpfreaks.com/topic/25349-case-statement-with-stock-level-not-working-solved/#findComment-115571 Share on other sites More sharing options...
mAdMaCCa Posted October 27, 2006 Author Share Posted October 27, 2006 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 :PAny chance you can point me in the right direction???CheersmAdMaCCa Link to comment https://forums.phpfreaks.com/topic/25349-case-statement-with-stock-level-not-working-solved/#findComment-115577 Share on other sites More sharing options...
Barand Posted October 27, 2006 Share Posted October 27, 2006 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 addingecho $product_info['products_price']; (or whatever the correct field is now) Link to comment https://forums.phpfreaks.com/topic/25349-case-statement-with-stock-level-not-working-solved/#findComment-115581 Share on other sites More sharing options...
mAdMaCCa Posted October 27, 2006 Author Share Posted October 27, 2006 All Sorted! ;DThanx for all your help! Link to comment https://forums.phpfreaks.com/topic/25349-case-statement-with-stock-level-not-working-solved/#findComment-115594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.