new_php85 Posted September 10, 2008 Share Posted September 10, 2008 iiii see again.... i have problem to search data by month and year... little bit explanation: end user need to select month and year in order to search the record.both month and year using drop down named month and year. this is sample code that i have made.. if (isset($_POST['month'])) && (isset($_POST['year']))) {( $month=$_POST['month']; $year=$_POST['year']; if($year=='year') && ($month=='month') { $q = "SELECT * FROM pe WHERE staff_id='$staff_id' AND month like '%$month%' AND year like '$year%'"; $result = mysql_query($q) or die('Query failed. ' . mysql_error()); $q2 = "SELECT SUM(shell) AS total_shell FROM pe WHERE staff_id='$staff_id' AND month like '%$month%' AND year like '$year%'"; $result2 = mysql_query($q2) or die('Query failed. ' . mysql_error()); $row2 = mysql_fetch_array($result2); $q3 = "SELECT SUM(cash) AS total_cash FROM pe WHERE staff_id='$staff_id' AND month like '%$month%' AND year like '$year%'"; $result3 = mysql_query($q3) or die('Query failed. ' . mysql_error()); $row3 = mysql_fetch_array($result3); $q4 = "SELECT SUM(tp_pe) AS total_tp_pe FROM pe WHERE staff_id='$staff_id' AND month like '%$month%' AND year like '$year%'"; $result4 = mysql_query($q4) or die('Query failed. ' . mysql_error()); $row4 = mysql_fetch_array($result4); } else { $q = "SELECT * FROM pe WHERE staff_id='$staff_id'"; $result = mysql_query($q) or die('Query failed. ' . mysql_error()); $q2 = "SELECT SUM(shell) AS total_shell FROM pe WHERE staff_id='$staff_id'"; $result2 = mysql_query($q2) or die('Query failed. ' . mysql_error()); $row2 = mysql_fetch_array($result2); $q3 = "SELECT SUM(cash) AS total_cash FROM pe WHERE staff_id='$staff_id'"; $result3 = mysql_query($q3) or die('Query failed. ' . mysql_error()); $row3 = mysql_fetch_array($result3); $q4 = "SELECT SUM(tp_pe) AS total_tp_pe FROM pe WHERE staff_id='$staff_id'"; $result4 = mysql_query($q4) or die('Query failed. ' . mysql_error()); $row4 = mysql_fetch_array($result4); } } ?> Why i can't get the output ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/123556-solved-how-to-do-searching-using-year-and-month/ Share on other sites More sharing options...
budimir Posted September 10, 2008 Share Posted September 10, 2008 You have a problem here: $q = "SELECT * FROM pe WHERE staff_id='$staff_id' AND month like '%$month%' AND year like '$year%'"; It should be: $q = "SELECT * FROM pe WHERE staff_id='$staff_id' AND month like '%$month%' AND year like '%$year%'"; Also, try to echo your "q" query? I can't see from wher you are getting $staff_id?? Quote Link to comment https://forums.phpfreaks.com/topic/123556-solved-how-to-do-searching-using-year-and-month/#findComment-638137 Share on other sites More sharing options...
teng84 Posted September 10, 2008 Share Posted September 10, 2008 You have a problem here: $q = "SELECT * FROM pe WHERE staff_id='$staff_id' AND month like '%$month%' AND year like '$year%'"; It should be: $q = "SELECT * FROM pe WHERE staff_id='$staff_id' AND month like '%$month%' AND year like '%$year%'"; Also, try to echo your "q" query? I can't see from wher you are getting $staff_id?? where is the diff in your code? and yes echo the query and post here and also what are the data type of your year and month? Quote Link to comment https://forums.phpfreaks.com/topic/123556-solved-how-to-do-searching-using-year-and-month/#findComment-638142 Share on other sites More sharing options...
JasonLewis Posted September 10, 2008 Share Posted September 10, 2008 budimir placed another % in front of $year. Quote Link to comment https://forums.phpfreaks.com/topic/123556-solved-how-to-do-searching-using-year-and-month/#findComment-638143 Share on other sites More sharing options...
teng84 Posted September 10, 2008 Share Posted September 10, 2008 my bad .. but one more thing is that why are you using %? i suppose this should be exact matches Quote Link to comment https://forums.phpfreaks.com/topic/123556-solved-how-to-do-searching-using-year-and-month/#findComment-638146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.