Hi i am back again as i have been thinking about the way i do my search and i think it would be better for me to get the content_general entry from this query rather than getting the ids. However this would mean i would have to get entries from more than one row in the content_english table.
So i have these table.
news table
id | headline | body | live
1 | 1 | 2 | 1
2 | 3 | 4 | 1
Content table
id | content_general
1 | "this is headline for new article id 1"
2 | "this is the body for news article id 1"
3 | "this is the headline for news article id 2"
4 | "this is the body for the news article id 2"
I have it like this because i have more than one language so I have content_english content_spanish.
Now the query i use (got from this thread, thanks) returns me the entry of the news article which satisfies the search result. So I added a little bit to give me the content field as well so i have this query now
SELECT n.* , c.content_general
FROM news n
INNER JOIN author a ON n.author=a.id
INNER JOIN content_english c ON c.id IN (n.headline, n.body)
AND (c.content_general LIKE '%test%' OR n.author LIKE '%test%')
AND n.live=1
However this means i still have to go back to the db to get the content_general field for the news title cause i only have an id for that entry with this query.
Now usually when i get the details of a news article i go back to get the content_general from the db with another query - this i know is not very efficient. For example, if i wanted to print to screen a news article i would get the details of the news article with a query
SELECT * FROM news WHERE id = 1
put it in $news
then for each content id i have i would go back to the db.
SELECT content_general FROM news WHERE id = '$news[headline]'
SELECT content_general FROM news WHERE id = '$news[body]'
So i would like to combine all these queries into one
I came up with this
SELECT c.content_general, c2.content_general
FROM content_english c, content_english c2, news n
WHERE c.id = a.headline
AND c2.id = a.body
AND a.id =7
And it works. However i am sure there is a more efficent way of doing it, plus the results are both named content_general and i was wondering if there was a way to name the result headings.
Hope this makes sense.
Thanks in advance for any help you can offer.