Jump to content

Search site


conker87

Recommended Posts

I'm trying to make a search form for my site. Just a quick question. This is my query:

 

$query = "SELECT * FROM `articles`, `reviews`
		WHERE `articles`.`title` LIKE '%$search%' OR
		`articles`.`author` LIKE '%$search%' OR
		`articles`.`type` LIKE '%$search%' OR
		`articles`.`content` LIKE '%$search%' OR
		`reviews`.`title` LIKE '%$search%' OR
		`reviews`.`genre` LIKE '%$search%' OR
		`reviews`.`platform` LIKE '%$search%' OR
		`reviews`.`author` LIKE '%$search%' OR
		`reviews`.`content` LIKE '%$search%'";

Where '$search' is the escaped query. Will this work? And can I use it with mysql_fetch_array/assoc?

Link to comment
https://forums.phpfreaks.com/topic/110027-search-site/
Share on other sites

$query = "SELECT * FROM `articles`, `reviews`
WHERE articles.title LIKE '%$search%' OR
articles.author LIKE '%$search%' OR
articles.type LIKE '%$search%' OR
articles.content LIKE '%$search%' OR
reviews.title LIKE '%$search%' OR
reviews.genre LIKE '%$search%' OR
reviews.platform LIKE '%$search%' OR
reviews.author LIKE '%$search%' OR
reviews.content LIKE '%$search%'";

 

No need for the ` when you referencing a table and column using table.column syntax. If you're doing a content search I would recommend you look into using MySQL's Full Text capabilities.

Link to comment
https://forums.phpfreaks.com/topic/110027-search-site/#findComment-564648
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.