PHP/MySQL Query In a loop, how to append to just one query?

Xhu|10

New Member
I have a query to pull all articles out of the database..\[code\]$get_articles = $db->query(" SELECT *, a.id AS id, s.type AS type FROM ".$prefix."articles a LEFT JOIN ".$prefix."sources s ON (s.id = source_id) WHERE a.type!='trashed' ORDER BY a.timestamp DESC LIMIT $start, $end");\[/code\]Within the loop of this query, I do then do another query on the same table to find related articles to the 'title' of the article, stored as '$related_phrase'. The query within the loop is:\[code\]// get related articles to this entry$get_related = $db->query(" SELECT *, a.id AS id, MATCH (title, description) AGAINST ('$related_phrase') AS score FROM ".$prefix."articles a LEFT JOIN ".$prefix."sources s ON (s.id = source_id) WHERE a.type!='trashed' AND MATCH (title, description) AGAINST ('$related_phrase') AND a.id!='$articles[id]' HAVING score > 7 ORDER BY a.timestamp DESC LIMIT 0, 3");\[/code\]This basically means we have a query in a loop which is causing the pages to load very slowly.What we want to do, is bring the query from within the loop, in the main query, so it's all working within one query, if that's possible?Any help very much appreciated!
 
Back
Top