Jump to content

greater than or equal to variable


madmega

Recommended Posts

Hi, i am trying to write a part of script for google shopping export, and all i want is that in this line, everything that is 0 or smaller, the line "pre-order" krijgt and everything that is 1 or greater the line "in stock"

This is what i've got now, but it doesn't work

I removed the rest of the long code.

 

$patterns = array();
$patterns[0] = '=<0';
$patterns[1] = '=>1';
$replacements = array();
$replacements[0] = 'vooraf bestellen';
$replacements[1] = 'op voorraad';

         if(OPTIONS_TONEN_FEED_AVAILABILITY == 1)
            $output .= "~" . preg_replace($patterns, $replacements, $row->quantity);

Link to comment
Share on other sites

I'm pretty sure that preg_replace doesn't work like that. To use a comparison operator, you could do something like:

 

<?php
//...

if($row->quantity     <= 0) { $output .= "~vooraf bestellen"; }
elseif($row->quantity >= 1) { $output .= "~op voorraad"; }

?>

 

 

Will there ever be values between 0 and 1?

Link to comment
Share on other sites

IT WORKED, your script did the trick...thank you !!!

 

Glad to hear. :D

 

Note that since it sounds like $row->quantity will never be between 0 and 1, you could skip the second test:

 

<?php
//...

if($row->quantity <= 0) { $output .= "~vooraf bestellen"; }
else                    { $output .= "~op voorraad"; }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.