Jump to content

[SOLVED] how to do searching using year and month


new_php85

Recommended Posts

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 ??? ??? ???

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??

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?

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.