Copy link to clipboard
Copied
Hi all,
A little riddle that I am sure is easy but have no idea how to do;
I have a list of products in a table and one of the cells contains this <?php echo $row_rsLanterns['product_Stock']; ?>. product_Stock has is a set value of either inStock and OutOfStock. I would llike to be able to display something different for each thing. I.E if the field contains inStock I would like to print In Stock and if OutOfStock then it displays Out of Stock. And also changes the colour of each one.
Any ideas would be great.
Thank you
Tom
<?php if ($row_rsLanterns['product_Stock'] == "inStock") { ?>
in stock stuff here. Add html or whatever message you want to let people know that product is in stock.
<?php } ?>
<?php if ($row_rsLanterns['product_Stock'] == "OutOfStock") { ?>
out of stock stuff here
<?php } ?>
Copy link to clipboard
Copied
<?php if ($row_rsLanterns['product_Stock'] == "inStock") { ?>
in stock stuff here. Add html or whatever message you want to let people know that product is in stock.
<?php } ?>
<?php if ($row_rsLanterns['product_Stock'] == "OutOfStock") { ?>
out of stock stuff here
<?php } ?>
Copy link to clipboard
Copied
Excellent, I haven't tried it out but that looks like it'll work fine.
Thanks so much.
Tom
Copy link to clipboard
Copied
Hi Tom,
Assuming table column for product_Stock can not be null and has a value of either inStock or OutOfStock you could optimize the script with an else statement instead.
If row value equals inStock then show inStock content. Else, meaning anything other than the row equaling inStock, which in this case would mean the row is theoretically OutOfStock by means of process of elimination, show the OutOfStock content. See example:
<?php if ($row_rsLanterns['product_Stock'] == "inStock") { ?>
In stock stuff here
<?php } else { ?>
Out of stock stuff here
<?php } ?>
best,
Shocker
Copy link to clipboard
Copied
To add to Shocker's excellent replies... DW will write the "If.. else" for you. Check out (the menus) Insert->PHP Objects. Also DW's help will go into further detail about this. Just seach it.
But you should read the PHP docs on the subject at: http://php.net/manual/en/control-structures.if.php
Make sure you also read about "elseif" and "switch". These are other control structures you'll probaby find useful.