php sql multiple search

I want to write a php code that can search for multiple keywords separated by a column. Currently my code is working accurately for a particular single keyword. Also; what changes should i make in the SQL table?

<?php
include('db.php');
if($_POST)
{
$q=$_POST['searchword'];
$sql_res = mysql_query("SELECT tag_id, tag_name FROM ttl_tags WHERE tag_name like '%$q%' ORDER BY tag_id LIMIT 5");
while($row=mysql_fetch_array($sql_res))
{
$tagid=$row['tag_id'];
$tagname=$row['tag_name'];
$re_tagname='<b>'.$q.'</b>';
$final_tagname = str_ireplace($q, $re_tagname, $tagname);

?>

Answers


If I am reading your question right, you want to search for multiple keywords in a single column? If so you can do:

 $sql_res = mysql_query("SELECT tag_id, tag_name FROM ttl_tags 
            WHERE tag_name like '%$q%' OR tag_name like 'ANOTHER_PARAMETER'  
            ORDER BY tag_id LIMIT 5"); 

You can put as many "OR"s that you want.


Need Your Help

Android: Different Java files for each view

java android android-activity header viewswitcher

I'm building an Android application which contains a fixed header with the application title in it. Right now, when the application changes activities, the header will slide out and slide in as well

MySQL database query client

mysql sql openfire

The database that is being used is MySQL database.