Jump to content

Recommended Posts

I'm looking to know the best way to process a search query that has multiple words in the search:

 

elseif(isset($_GET['search'])){
$search=$_GET['search'];
$keyword=explode(" ",$search);

//database query
}

 

Should I do a while loop query the database for each keyword?

Link to comment
https://forums.phpfreaks.com/topic/236530-search-system-multiple-keywords/
Share on other sites

alright, just making sure I'm on the right track here:

 

elseif(isset($_GET['search'])){
$search=$_GET['search'];
$keyword=explode(" ",$search);
$keywords=implode(",",$keyword);
$sql10000="SELECT product_id FROM $tbl_name2 WHERE keyword IN($keywords)";
$result10000=mysql($sql10000);
while($row10000=mysql_fetch_array($result10000)){
$product_id3=$row10000['product_id'];
$sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3;
mysql($sql15000);
}
}

The below is returning:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/zyquo/public_html/ghosthuntersportal.com/pages.php on line 39

 

Line 39 is, while($row10000=mysql_fetch_array($result10000)){

 

elseif(isset($_GET['q'])){
$search=$_GET['q'];
$keyword=explode("+",$search);
$keywords=implode(",",$keyword);
$sql10000="SELECT product_id FROM $tbl_name2 WHERE keyword IN($keywords)";
$result10000=mysql_query($sql10000);
while($row10000=mysql_fetch_array($result10000)){
$product_id3=$row10000['product_id'];
$sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3;
$result15000=mysql_query($sql15000);
while($row15000=mysql_fetch_array($result15000)){
extract($row1500);
$content=$product_id;
}
}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.