Hi everyone,
I am trying to write a search query for a keyword search on a web site.
I want to search through a few different tables and get just one result set back. i.e. i dont want to do multiple queries.
I am currently trying to do this with JOINs. I think i have done something wrong as i just lock up my local server when i run this query. Any suggestions would be great.
I think i need LEFT JOINS but i dont think i am doing it correcly.
In the code above "fish" is my keyword entered from the text box on site.
Thanks in advance for any tips.
I am trying to write a search query for a keyword search on a web site.
I want to search through a few different tables and get just one result set back. i.e. i dont want to do multiple queries.
I am currently trying to do this with JOINs. I think i have done something wrong as i just lock up my local server when i run this query. Any suggestions would be great.
I think i need LEFT JOINS but i dont think i am doing it correcly.
Code:
SELECT `area`.area1_desc, `area`.area2_desc, `city`.city_name, `features`.feature_title, `item_price_category`.price_cat_desc, `items`.item_name, `items`.item_bookstandfirst, `items`.item_url, `items`.item_AZcaption, `items`.item_AreaCaption, `items`.item_TypeCaption, `items`.item_goodValue, `practical_index`.pIndex_desc, `practicalities`.p_name, `travel`.travel_name, `useful_links`.link_desc
FROM `chapter` LEFT JOIN `city` ON `chapter`.chapter_id = `city`.city_id
LEFT JOIN `items` ON `chapter`.chapter_id = `items`.item_chapter_id
LEFT JOIN `calendar` ON `city`.city_id = `calendar`.entry_city_id
LEFT JOIN `practicalities` ON `city`.city_id = `practicalities`.p_city_id
LEFT JOIN `practical_index` ON `practical_index`.pIndex_id = `practicalities`.p_indexCat_id
LEFT JOIN `travel` ON `city`.city_id = `travel`.travel_city_id
LEFT JOIN `features` ON `city`.city_id = `features`.feature_city_id LEFT JOIN `useful_links` ON `chapter`.chapter_id = `useful_links`.link_chapter_id LEFT JOIN `item_price_category` ON `item_price_category`.price_cat_id = `items`.item_price_cat_id
LEFT JOIN `area` ON `area`.area_id = `items`.item_area2_id WHERE
`area`.area1_desc = '%fish%' OR
`area`.area2_desc = '%fish%' OR
`chapter`.chapter_lname = '%fish%' OR
`city`.city_name = '%fish%' OR
`features`.feature_title = '%fish%' OR `item_price_category`.price_cat_desc = '%fish%' OR `items`.item_name = '%fish%' OR
`items`.item_goodValue = '%fish%' OR `practical_index`.pIndex_desc = '%fish%' OR `practicalities`.p_name = '%fish%' OR
`travel`.travel_name = '%fish%' OR
`useful_links`.link_desc = '%fish%'
LIMIT 0,100;
In the code above "fish" is my keyword entered from the text box on site.
Thanks in advance for any tips.