Jump to content

[SOLVED] Trying to pull a search query with a | delimeter


jaxdevil

Recommended Posts

I am trying to make a search query that can display all the items in the database that match a phrase that is between two '|' symbols. I have a field in my database that is called 'cats' for categories, and since everything has multiple categories I seperate the different ones from each other with a '|' symbol. Now I am trying to pull them up  based on that using the following code and by sending the data to the page. I can't get it to work. Any ideas? By the way I use the same code and it works when there is just a single thing to search for in the cats field, not multiples with a delimeter and I just do a plain search like %cat1%.

 

Here is an example of whats in the `cats` field now:

 

consumer electronics|videogame console software|ps3 games

 

And here is the query string:

 

$result = mysql_query("SELECT count(*) FROM products WHERE `cats` LIKE '%|$cat1|%' OR `cats` LIKE '%|$cat2|%' OR `cats` LIKE '%|$cat3|%'") or die(mysql_error

 

I appreciate any help guys :)

 

Link to comment
Share on other sites

Duh! My bad. Consumer electronics was that I was testing the search with, and it only has the delimiter AFTER the name, not before. Dooh (as homer would say) Ah well, third times the charm :)

 

Thank anyways people, hope this helps someone looking for the same answer.

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.