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' PHP: what am i missing. thanks
Post the full code, as I can indentify a few syntax errors with your $sql already, but posting more code would make me understand your structure better.
i'm not sure what you wanna say with your sql query, but it doesn't look normal to me .. especially the punctuation before the $search1 not much to understand from your short post, but i'll give it a shot .. did you want to write the following ? $sql = "SELECT * FROM topic WHERE Title LIKE '%$search1%' AND req='1' "; I've surrounded the wholel line with double quotes, removed the unknown punctuation before the wildcarded variable and removed the () since you don't need them in this particular case. You might also want to surround the field name "Title" with `....` (the thing just under your ESC button on keyboard) .. so it will look like `Title`.
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"; } Code (markup): my html is <select name="req" id="req"> <option value="1">yes</option> <option value="2">no</option> </select> Code (markup): i am already putting the values into the database using this: $sql = 'INSERT INTO topic (req) VALUES '." ('$_SESSION[EmpId]', $req)"; Code (markup): 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; } Code (markup): what u think?
are you getting any error or wrong result?? You haven't specified what problem you are facing>> If it runs well then you are missing nothing But if it is not working then you are missing to write your question here for now
it just doesn't work.. im trying to do it like here http://www.insiderpages.com/store_finder/find/home_depot where u search by something and then by state, just that i will put just 2 options in the state drop box thanks
This is clearly wrong: 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; } Code (markup): the if statment is wrong... I would do something like: if($search1 == '') { $smarty->assign('Error','Please enter any destination!'); $z=1; } if($type == 'like' && $status='1') { $req = intval ($_POST['req']); $sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%')"; if ($req > 0 && $req < 3) $sql .= " AND req= $req"; //... } Code (markup): As far as I understand it you want to narrow down the results IF the req has been chosen. Could be wrong though lol aXe
i tryed this $req = intval ($_GET['req']); if($type == 'like' && $status='1' && $req > 0 && $req < 3) { $sql = "SELECT * FROM topic WHERE (Title LIKE '%$search1%') AND req= $req""; } it worked. thanks a lotttttttttt Code (markup):