Forum Moderators: coopster

Message Too Old, No Replies

Multiple LIKE searches?

         

mattpointblank

11:28 pm on Nov 26, 2005 (gmt 0)

10+ Year Member



Hey everyone,

I'm running a review database site and I'm displaying links underneath reviews called 'related reviews'. Here's what it's doing:

$relquery = "SELECT id, Band_Name, Record_Name FROM reviews WHERE Band_Name LIKE '%$Band_Name%' AND id NOT LIKE $id ORDER BY Band_Name, Record_Name";

This works fine except in the case of split releases. For example:

Two bands: Xiu Xiu, Devendra Banhart

We have reviews by both artists, and now, a split release they did together. On this record, the $Band_Name value is "Xiu Xiu / Devendra Banhart", so my LIKE search above finds nothing.

I then tried this:

$exploder = explode(' / ', $Band_Name);
$related1 = $exploder[0];
$related2 = $exploder[1];

$relquery = "SELECT id, Band_Name, Record_Name FROM review_test WHERE Band_Name LIKE '%$related1%', '%$related2%' AND id NOT LIKE $id ORDER BY Band_Name, Record_Name";

The above didn't work, so I changed it to search for just:

LIKE '%$related1%'

This then found the Xiu Xiu stuff but not the other artist.

Is there any way I can work around this and somehow search both?

-Matt

hiker_jjw

2:02 am on Nov 27, 2005 (gmt 0)



You might want to rethink your "relational" database. You can add a lookup table or two. Otherwise, you might try using regular expressions instead of the LIKE statements.

Jeff

directrix

7:01 pm on Nov 28, 2005 (gmt 0)

10+ Year Member



You can do:

$relquery = "SELECT id, Band_Name, Record_Name FROM review_test WHERE (Band_Name LIKE '%$related1%' or Band_Name LIKE '%$related2%') AND id NOT LIKE $id ORDER BY Band_Name, Record_Name";

But test what happens when $related2 is blank or empty.