Help with an "If statement"

I have a piece of code for an online store I am building in order to sell some themes. I have the code that pulls random themes out of my database but I want to have more than one. I need a statement that would say not to pull the same one out. I know it would be an "If statement but can’t figure out quite how to word it. Can someone please direct me a little bit so I can get this done. Thanks

<?=$image?> <?=$itemname?> - <?=$catlink?>

<?=$blurb?>... read more

Price: <?=$currsymbol?><?=$itemprice?> <?=$currcode?>  

<?=$image?> <?=$itemname?> - <?=$catlink?>

<?=$blurb?>... read more

Price: <?=$currsymbol?><?=$itemprice?> <?=$currcode?>  

If you are wanting several items to show at random, but not all the same item then perhaps an array is more of what you need as opposed to an elseif or if statement…if I understand correctly what you are trying to do. 8)

for example…

<?php if($variable1 == "item1"){ echo "some command line goes here or group of commands"; }else{ echo "some alternate command line goes here or an alternate group of commands"; } ?>

Otherwise I would suggest an associative array because I really think that is more of what you are looking for.
For example…

$theme["default"] = defaultpath; $theme["summer"] = summerpath; $theme["winter"] = winterpath; $theme["spring"] = springpath; $theme["fall"] = fallpath; $theme["clouds"] = cloudspath;
Would be used to load the entire set of themes into a single variable. Then we just call to it for display, and a very simple example of this (if it were a display item) would be…

echo " I prefer a <a href='$theme[spring]'> Spring</a> theme.";

Of course the code to activate a site theme will be much more than that simple link to a theme portal dealio I put in here, but that should give you the general idea. If this helps I can give you a couple of tutorial URLs to check out that I used to learn this very area of PHP for my needs.

As LrdDark says, an array is the way to go: you could for example loop 3 times through your random code with an if statement checking if the picked theme is already present in array $displayedthemes. If not, add the picked theme to the array. If so, go back to picking a random theme again.

Sponsor our Newsletter | Privacy Policy | Terms of Service