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

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

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?

Archived

This topic is now archived and is closed to further replies.

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