I’m sorry if this is the wrong place to ask this, seeing as I hardly ever use pure SQL and I usually do everything through PHP, I thought I’d ask here - but if it’s the wrong place, I apologize.
I’m trying to code a search feature into a website. The search feature needs to search multiple tables for the keywords used and then paginate the results.
I tried this with separate queries at first, which worked but was impossible to paginate properly, so I’m now trying to do it all in the one query - Problem is the query is taking a while and returning “MySQL client ran out of memory”.
I’m not using joins (or at least, not properly if I am) and don’t really get how they wok as everything I’ve ready up about them thus far seems to try to match identical data between tables/columns, whereas I just need to see if a keyword exists in each of the tables/columns.
The code I’m using for the query is:
[embed=425,349]
$sql = “SELECT * FROM
subsections,
products,
pages,
blog_entries
WHERE
subsections.name LIKE '%”.mysql_real_escape_string($keywords)."%’ OR
subsections.description LIKE ‘%".mysql_real_escape_string($keywords)."%’ OR
products.code LIKE ‘%".mysql_real_escape_string($keywords)."%’ OR
products.name LIKE ‘%".mysql_real_escape_string($keywords)."%’ OR
products.description LIKE ‘%".mysql_real_escape_string($keywords)."%’ OR
pages.title LIKE ‘%".mysql_real_escape_string($keywords)."%’ OR
pages.content LIKE ‘%".mysql_real_escape_string($keywords)."%’ OR
blog_entries.name LIKE ‘%".mysql_real_escape_string($keywords)."%’ OR
blog_entries.content LIKE ‘%".mysql_real_escape_string($keywords)."%’";
[/embed]
Would someone mind helping me do this properly?
Cheers,
- V.