0

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);

?>
3
  • how many keywords at maximum would you search for? Commented Jun 12, 2012 at 14:03
  • and what is the expected max size of ttl_tags? In number of different tags OR number of total rows? (more or less...) Commented Jun 12, 2012 at 14:12
  • max. size of ttl_tags will be three. ttl_id is an id given to ttl_tags.. eg: "1";"blue"==> ttl_id=1 & ttl_tags=blue. The user will search for key-words aka ttl_tags Commented Jun 12, 2012 at 14:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.