A quick and simple way to search a MySQL database. Example: mysqlsearch('items', 'title tags', isset($GET['q'])?$GET['q']:'', Array('columns'=>'*', 'method'=>'OR', 'extrasql'=>'AND active = "true" ORDER BY id DESC'));
$pattern = '/([[:alpha:]:]+)([[:alpha:] ]+)[[:alpha:]]?+[ ]?/i'; $query = $regs[0]; $column = $columns; for ($i = 0; $i < count($column_list); $i++) { $sql[] = '' . $column_list[$i] . ' REGEXP "' . $keywords . '"'; } } $results = mysql_fetch_results(mysql_query('SELECT ' . $options['columns'] . ' FROM ' . $table . ' WHERE ' . $sql_query . ' ' . $options['extra_sql'])); return $results; } }
Comments
Subscribe to comments
You need to login to post a comment.

Is this designed for FULLTEXT searching, or LIKE matching?
Also, do you have a version with comments?
Hey Neo Geek,
Thanks for the great little snipplet,
In order to search alpha & numeric values I changed the pattern accordingly, $pattern = '/([[:alnum:]:]+)([[:alnum:] ]+)[[:alnum:]]?+[ ]?/i'; It worked for normal searches like "apple" and "1234" howevr when I search for"1234-htry-3345" it splits the query at the "-" to an array of ("1234", "htry", "3345") and the search fails. My Regex knowledge leaves a lot to be desired, please would you explain where I'm goig wrong if I would like to search for the above term?
Thanks in advance, Roark
You should add something like an example.. Some people don't understand this, you know.
Regards, Oussama.
You should add something like an example.. Some people don't understand this, you know.
Regards, Oussama.