Jump to content

How do I give user selection of fields to search with Full Text - Boolean?


Recommended Posts

I want to give the user the option of searching a combination of the fields $Topic, $Subtopic, $Theswords in Boolean/Full Text. The problem is if I make any of the fields empty prior to the query, I get a MySql syntax error message. The user has the option of selecting fields via checkboxes, but when the field is not selected the user will get the error message. Is there any way of avoiding the error message when a field is not selected to be searched? Thank you in advance for any replies.

 

 

$query = "SELECT * FROM `View2_CondFT` WHERE MATCH($TopicFieldSelect, $SubtopicFieldSelect, $TheswordsFieldSelect) AGAINST ('$terms[0]' IN BOOLEAN MODE) 
AND MATCH($Topic, $Subtopic, $Theswords) AGAINST ('$terms[1]' IN BOOLEAN MODE) 
AND MATCH($Topic, $Subtopic, $Theswords) AGAINST ('$terms[2]' IN BOOLEAN MODE) 
AND MATCH($Topic, $Subtopic, $Theswords) AGAINST ('$terms[3]' IN BOOLEAN MODE) 
AND MATCH($Topic, $Subtopic, $Theswords) AGAINST ('$terms[4]' IN BOOLEAN MODE) 
AND MATCH($Topic, $Subtopic, $Theswords) AGAINST ('$terms[5]' IN BOOLEAN MODE) 
ORDER BY `Lnum` ASC ;

Thank you Illusion, you are right I posted this question to the wrong forum. Oops.

 

Is there any way you could further explain what you mean by the part of your statement shown below?

 

"then append a match conditon for the query, like that for all the check boxes."

 

Thank you again for the response.

$query = "SELECT * FROM `View2_CondFT` ";
$isand=0;
if(isset($terms[1]) and $isand==0)
{
$query=$query."MATCH($Topic, $Subtopic, $Theswords) AGAINST ('$terms[1]' IN BOOLEAN MODE)";
$isand=1;
}
if(isset($terms[2]) and $isand==0)
{
$query=$query."MATCH($Topic, $Subtopic, $Theswords) AGAINST ('$terms[1]' IN BOOLEAN MODE)";
$isand=1;
}
elseif(isset($terms[2]) and $isand==1)
{
$query=$query."AND MATCH($Topic, $Subtopic, $Theswords) AGAINST ('$terms[1]' IN BOOLEAN MODE)";
}

like that test for all check boxes and built the query..........I am not reviewd it .....

 

 

 

 

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.