Jump to content

filter results by using search box and drop down


patrioticcow

Recommended Posts

hello.

i have a search box that will display some results. I also have a drop down list with values "1" and "2".

the values for each results are stored into database in a "req" field.

 

<select name="req" id="req">
           <option value="1">yes</option>
           <option value="2">no</option>
</select>
$sql = 'SELECT * FROM topic WHERE (Title LIKE '."'%$search1%') AND req='1'

 

what am i missing.

thanks

Link to comment
Share on other sites

You should be able to simply use the value of $_POST['req'] in the query string.

 

$_POST=['req'] = trim($_POST['req']);
if( $_POST['req'] == 1 || $_POST['req'] == 2 ) {
     $req = (int) $_POST['req'];
} else {
     // If field is empty, or not equal to 1 or 2, set a default (or whatever you'd like)
     $req = 1;
}

$sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req";

Link to comment
Share on other sites

i've got a little problem integrating the code into my code

 

if($search1 == '')
{
	$smarty->assign('Error','Please enter any destination!');
	$z=1;
}
elseif($type == 'like' && $status='1')
  	{
$sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req";
}

 

my html is

<select name="req" id="req">
           <option value="1">yes</option>
           <option value="2">no</option>
</select>

i am already putting the values into the database using this:

$sql = 'INSERT INTO topic (req) VALUES '." ('$_SESSION[EmpId]', $req)";

 

let me see if i got the right idea on how I should implement the code


if($search1 == '')
{
	$smarty->assign('Error','Please enter any destination!');
	$z=1;
}
if( $_POST['req'] == 1 || $_POST['req'] == 2 ) {
     $req = (int) $_POST['req'];
}
elseif($type == 'like' && $status='1')
  	{
$sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req";
$req = 1;
}

what u think?

Link to comment
Share on other sites

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.