funbinod Posted May 15, 2014 Share Posted May 15, 2014 i'm trying to get make query relating to the date selection. and if no date is selected, i want to make default query without date selection. for this i tried this ---- // above this there is a form with two input fields for from date and to date selection with a submit buttom. action is $_SERVER['PHP_SELF']if (!isset($_POST['sort'])) { // 'sort' is the submit button name$query = "SELECT * FROM tran WHERE ssn!=0 ORDER BY date";} else { $fdate == $_POST['fdate']; // from date $tdate == $_POST['tdate']; // to date$query = "SELECT * FROM tran WHERE ssn!=0 AND date BETWEEN '$fdate' AND '$tdate' ORDER BY date";} but this is not working... any suggestion!!!????? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 15, 2014 Share Posted May 15, 2014 You tried to use == to assign a value, that doesn't work. == is for comparison. Link to comment Share on other sites More sharing options...
funbinod Posted May 15, 2014 Author Share Posted May 15, 2014 You tried to use == to assign a value, that doesn't work. == is for comparison. this means single = (or something else) would work? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 15, 2014 Share Posted May 15, 2014 Yes, = is for assignment. == and === are for comparison. Link to comment Share on other sites More sharing options...
funbinod Posted May 16, 2014 Author Share Posted May 16, 2014 single = is also not working. if (!isset($_POST['sort'])) {$query = "SELECT * FROM tran WHERE ssn!=0 ORDER BY date";} else {$fdate = $_REQUEST['fdate'];$tdate = $_REQUEST['tdate'];$query = "SELECT * FROM tran WHERE ssn!=0 AND date BETWEEN '$fdate' AND '$tdate' ORDER BY date";} it returns the query on if statement. but even after selecting the date it is the query from if statement (or simply the if, else statement is not working).. Link to comment Share on other sites More sharing options...
birbal Posted May 16, 2014 Share Posted May 16, 2014 Check what does $_POST['sort'] returns. Use var_dump() Link to comment Share on other sites More sharing options...
justsomeguy Posted May 16, 2014 Share Posted May 16, 2014 Believe me, if statements in PHP work just fine. It is doing exactly what you are telling it to do. The value that you are checking in the if statement is true. Link to comment Share on other sites More sharing options...
funbinod Posted May 17, 2014 Author Share Posted May 17, 2014 (edited) there is no reason not to believe u. i'm nothing in comparison to a php tycoon like u. i was just asking for other possible reasons for it. and now i found it. shame on me. i just forgot to place method="post" into the form. thank u for ur company. Edited May 17, 2014 by funbinod Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now