Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PHP IF statement?


slackbladder

Recommended Posts

Hi,

 

Sry for my newbie question :? but I only ever hacked code never tried creating it myself (lazy!).

 

Is it possible to have this senario:

 

Instead of being presented with a list of sub-categories in the centre (after clicking on a main category of the left), can an image appear in the centre instead. An image that is only associated to that category?

 

So:

If a user clicks on the TOYS category on the left, he is presented with a TOY image in the middle but nothing else. On the left the TOY category will expand to include all sub-categories.

If the user then clicks on the CLOTHING category on the left, the image in the midddle changes to a CLOTHING image and so on.....

 

I am able to delete the CATEGORY code from default.php so it doesn't display sub-categories in the middle and even place a simple 'img' tag so each category displays the same image, but can I use an 'IF' statement to display a preset image for each category.

 

E.G.

 

IF cPath = 25 then img = /path/to/img1

IF cPath = 23 then img = /path/to/img2

IF cPath = 21 then img = /path/to/img3

 

etc.

 

 

Sorry if this seems confusing (I managed to confuse myself while writing it

:D )

 

Any help would be much appreciated.

 

Thx

Link to comment
Share on other sites

Yes, you could use if/else statements. It would even be easier to use switch/case statements. There is a description of them here.

In olden times the men were made of iron and the ships were made of wood; now it's the other way around. :wink:

Link to comment
Share on other sites

Thx for that :D

 

However with either approach I still don't know how to use the code.

 

I'm guessing the variable cPath is used - but how?

 

My knowledge of PHP is pretty basic i'm afraid.

 

Any other suggestions?

 

Many thx

Tony

Link to comment
Share on other sites

I think you want something like this:

$img = ''; // not sure you need this

switch( $cPath )

{

   case 25:

       $img = 'path/to/img1';

       break;

   case 23:

       $img = 'path/to/img2';

       break;

   case 21:

       $img = 'path/to/img3';

       break;

   default:

       $img = 'path/to/defaultImg';

}

Then wherever you are using it, you put something like:

echo '<img src=' . $img . '>';

In olden times the men were made of iron and the ships were made of wood; now it's the other way around. :wink:

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...