Selecting from 2 MySQL database tables
Posted: Wed May 14, 2008 9:15 pm
I have listings in my mysql database in their own table. I also have custom fields in another table which hook up to the listings.
Basically I want to enable people to search both the listing table and the custom fields table.
Here is my code:
This works fine however if there are no rows in the listings_customfields table for the listing, it is ignored in the search even if the keyword exists in the listings_items table.
Any idea on how I can make it still show results if nothing exists in the listings_customfields table?
Basically I want to enable people to search both the listing table and the custom fields table.
Here is my code:
Code: Select all
$listings_query = mysql_query("SELECT * FROM listings_items AS l JOIN listings_customfields AS c ON l.id = c.listingid WHERE
l.title rlike '".make_safe($search_keywords)."' or
l.code rlike '".make_safe($search_keywords)."' or
l.summary rlike '".make_safe($search_keywords)."' or
l.description rlike '".make_safe($search_keywords)."' or
c.value rlike '".make_safe($search_keywords)."'
GROUP BY l.id") or die(mysql_error());Any idea on how I can make it still show results if nothing exists in the listings_customfields table?