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 :)

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.