Hello,
My current code is -
if ($similar[‘prodPrice’] == 0.00) {
I am looking to list out 0.00 1.00 2.00 etc up to 5.00.
Could someone share how I would need to write it out?
Thanks in advance!
Hello,
My current code is -
if ($similar[‘prodPrice’] == 0.00) {
I am looking to list out 0.00 1.00 2.00 etc up to 5.00.
Could someone share how I would need to write it out?
Thanks in advance!
AFAIK there’s usually not much difference between using || or OR
But there is a difference in “precedence”. I usually avoid any potential problems by putting things in parentheses instead of thinking about precedence issues.
It my do the trick, but I don’t think that it does it very well.
The first thing to do is to remove a vast amount of duplication. Assign $row_product[‘prodPrice’] to a separate variable, so that the array is referenced only once.
$price = $row_product['prodPrice'];
if($price == 0.00 or $price == 1.00 or $price == 2.00 or $price == 3.00 or $price == 4.00 or $price == 5.00) {
$box_content->assign("PRICE",$theTitle.'<span>- See store for pricing</span><br />');
}
Now it’s clear that we’re checking if the price is 5 or less, and if the price is equal to the nearest dollar.
$price = $row_product['prodPrice'];
$nearestDollar = intval($price);
if ($price >= 0 && $price <= 5 && $price == $nearestDollar) {
$box_content->assign("PRICE",$theTitle.'<span>- See store for pricing</span><br />');
}
That seems to be a clearer and easier to understand way of doing things.
Like this?
if($similar['prodPrice'] == 4.55){
$box_content->assign("PRICE",$theTitle.'<span>- See store for pricing</span><br />');
}
On another note, using the below range solution:
if($similar[‘prodPrice’] > 0.00 && $similar[‘prodPrice’] <= 5.00){
$box_content->assign(“PRICE”,$theTitle.‘<span>- See store for pricing</span><br />’);
Is there a simple modification that will only specify the exact values?
I would still like to see for example 4.55 or 2.35, etc. I am just trying to exclude and rename the prodPrice if it is a match to the whole dollar amount being 1.00 2.00 3.00 4.00 5.00.
I really like the range method as it is a major code saver, I really appreciate your help.
Thanks,
Yes. You can use any expression within the if-statement that fits the logic of what you need.
$value==1.35
$value==1.50 || $value==2.00
$value>=1.50 && $value<=2.50
…and so on and so forth.
Well, your last post opened my eyes.
The code below does the trick:
if($row_product['prodPrice'] == 0.00 or $row_product['prodPrice'] == 1.00 or $row_product['prodPrice'] == 2.00 or $row_product['prodPrice'] == 3.00 or $row_product['prodPrice'] == 4.00 or $row_product['prodPrice'] == 5.00){
$box_content->assign("PRICE",$theTitle.'<span>- See store for pricing</span><br />');
Thank you for working with me while I sorted my issue out.
$value >=0.00 && $value<=0.99
Excellent, the range example is a perfact solution. Thanks the help!
Thanks for the help, I did not have any luck getting this to work in my system. Do you have any other methods you could mention?
Thanks again,
“do something;” is just filler. You can remove that and put your own code in.
Or, if prices are listed in your database, this might be more of a database question instead.
Of course, I attempted to modify to integrate to the surrounding code however it didn’t seem to set right. Essentially, I am trying to tell the system that if 0.00 to 5.00 then specify “text here”.
I had success with the following, though only up to 1.00 using an if if:
if ($similar[‘prodPrice’] == 0.00) {
$box_content->assign(“PRICE”,$theTitle.‘<span>- See store for pricing</span><br />’);}
if ($similar[‘prodPrice’] == 1.00) {
$box_content->assign(“PRICE”,$theTitle.‘<span>- See store for pricing</span><br />’);
Would you happen to know of another way to list up to 5.00?
Thanks!
The switch statement will do that.
http://php.net/manual/en/control-structures.switch.php
If you want to use if-statements, I suggest if-else.
Or, if you want to specify a range:
if($similar['prodPrice'] > 0.00 && $similar['prodPrice'] <= 5.00){
$box_content->assign("PRICE",$theTitle.'<span>- See store for pricing</span><br />');}
}
Well if I’m understanding your question, try this
switch ($similar[‘prodPrice’]) {
case 0.00:
do something;
break;
case 1.00:
do something;
break;
case 2.00:
do something;
break;
case 3.00:
do something;
break;
case 4.00:
do something;
break;
case 5.00:
do something;
break;
}
Thanks, I will modify that. Just curious what is the significance between the use of the “||” or the “or” in this case?
It is looking like I will need to give multiple ranges 0.01 - 0.99 and then specify the whole value 0.00 etc.
I am sure I thinking too hard on writing this out. One of those frustrating code blocks.
You should be using || (double pipe) for the OR operator.
My apologies for the redundancy, would you mind sharing a last quick example of how this will look.
Thanks again,