Jump to content

Help to combine two very simple codes with OR


dimko

Recommended Posts

I have this part of the code:

 

        for($number_words_loop = 0; $number_words_loop < $number_words; $number_words_loop++) 
       { 
        $value1 .= 'AND a.adtitle RLIKE \'[[:<:]]' . $words[$number_words_loop] . '[[:>:]]\''; 
        $value2 .= 'AND a.addesc RLIKE \'[[:<:]]' . $words[$number_words_loop] . '[[:>:]]\''; 
       } 

 

And I want to combine $value1 and $value2, so the code should look something like this:

 

        for($number_words_loop = 0; $number_words_loop < $number_words; $number_words_loop++) 
       { 
        $value .= 'AND a.adtitle RLIKE \'[[:<:]]' . $words[$number_words_loop] . '[[:>:]]\' OR AND a.addesc RLIKE \'[[:<:]]' . $words[$number_words_loop] . '[[:>:]]\''; 
       } 

 

In the first code, first it checks $value1 and then $value2 one by one, and that way it checks if both of them contain all the words that are put in the search field. What I need is to check if all the words that are put in the search field are contained in the one OR in the another. I want to make it search through both of them at the same time, but I don't know how to put correctly that OR I put in the second example. So any professional help will be appreciated.

 

Here is an example of what I mean:

 

If the Ad has this:

 

Ad Title: nokia phone on sale

Ad Description: brand new, unpacked, with 16gb memory card included.

 

and if someone searches for nokia sale it will show the ad, because all the search words are contained in the Ad Title. Also, if the search is brand unpacked it will also show the ad, because all the search words are contained in the Ad Description. But, the problem is if someone searches for nokia brand This way, the word nokia is not contained in the Ad Description, and the word brand is not contained in the Ad Title, so the ad will not be shown.

 

So, I only need a way to put that OR correctly to connect those two values, just like the second code, but in the right way.

 

Thanks in advance.

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.