Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Display field differently depending on content. PHP MYSQL

Explorer ,
Jun 23, 2011 Jun 23, 2011

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

TOPICS
Server side applications

Views

704
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jun 23, 2011 Jun 23, 2011

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

Votes

Translate
Guest
Jun 23, 2011 Jun 23, 2011

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 23, 2011 Jun 23, 2011

Copy link to clipboard

Copied

Excellent, I haven't tried it out but that looks like it'll work fine.

Thanks so much.

Tom

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 23, 2011 Jun 23, 2011

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 23, 2011 Jun 23, 2011

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines