Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created July 3, 2012 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/3040211 to your computer and use it in GitHub Desktop.
Save walterdavis/3040211 to your computer and use it in GitHub Desktop.
<?php
$sql = 'SELECT * FROM table_name WHERE 1 AND';
$q = mysql_real_escape_string($_REQUEST['q']);
switch($_REQUEST['find_in']){
case 'Comments':
$sql .= ' comments LIKE "%' . $q . '%"';
break;
case 'Titles':
$sql .= ' title LIKE "%' . $q . '%"';
break;
default:
$sql .= ' CONCAT(comments, ' ', title, ' ', body) LIKE "%' . $q . '%"';
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment