Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.