patrioticcow Posted September 18, 2010 Share Posted September 18, 2010 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 https://forums.phpfreaks.com/topic/213711-filter-results-by-using-search-box-and-drop-down/ Share on other sites More sharing options...
Pikachu2000 Posted September 18, 2010 Share Posted September 18, 2010 It isn't really clear what your question is. Link to comment https://forums.phpfreaks.com/topic/213711-filter-results-by-using-search-box-and-drop-down/#findComment-1112366 Share on other sites More sharing options...
patrioticcow Posted September 18, 2010 Author Share Posted September 18, 2010 i want the results to be filtered by choosing YES or NO. more specific 1 or 2. each result has already the values 1 or 2 added to them in the database Link to comment https://forums.phpfreaks.com/topic/213711-filter-results-by-using-search-box-and-drop-down/#findComment-1112396 Share on other sites More sharing options...
Pikachu2000 Posted September 18, 2010 Share Posted September 18, 2010 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 https://forums.phpfreaks.com/topic/213711-filter-results-by-using-search-box-and-drop-down/#findComment-1112434 Share on other sites More sharing options...
patrioticcow Posted September 20, 2010 Author Share Posted September 20, 2010 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 https://forums.phpfreaks.com/topic/213711-filter-results-by-using-search-box-and-drop-down/#findComment-1113125 Share on other sites More sharing options...
Pikachu2000 Posted September 20, 2010 Share Posted September 20, 2010 One type in yours that I noticed, should be status == elseif($type == 'like' && $status='1') Link to comment https://forums.phpfreaks.com/topic/213711-filter-results-by-using-search-box-and-drop-down/#findComment-1113297 Share on other sites More sharing options...
patrioticcow Posted September 22, 2010 Author Share Posted September 22, 2010 i found the answer thanks to -->axelay $req = intval ($_GET['req']); if($type == 'like' && $status='1' && $req > 0 && $req < 3) { $sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req""; } Link to comment https://forums.phpfreaks.com/topic/213711-filter-results-by-using-search-box-and-drop-down/#findComment-1114012 Share on other sites More sharing options...
Pikachu2000 Posted September 22, 2010 Share Posted September 22, 2010 You still need to change $status = '1' to $status == '1' . . . Link to comment https://forums.phpfreaks.com/topic/213711-filter-results-by-using-search-box-and-drop-down/#findComment-1114084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.