HELP REGARDING SEARCHING BETWEEN MONTHS REQUIRED

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abdulquddus
Forum Newbie
Posts: 1
Joined: Tue Oct 11, 2011 10:49 pm

HELP REGARDING SEARCHING BETWEEN MONTHS REQUIRED

Post by abdulquddus »

FIRST OF ALL I AM SORRY IF I HAD MADE QUESTION AT WRONG THREAD.

MY QUESTION IS THIS I WANT TO SEARCH BETWEEN MONTHS IN WHICH FIRST MONTH IS SET AS DEFAULT AND NEXT IS CHOSEN BY THE USER. TAKE IT AS IF A FEES DEFAULTER HAS TO BE FOUND HIS/HER STUDENT ID IS SCANNED WHILE TAKING FROM THE REGISTRATION RECORD THEN GOING IN THE FEES COLLECTION RECORD WHICH HAS THE FEE COLLECTION MONTH COLUMN. AFTER SCANNING IT RETURNS ALL THE MONTHS THAT ARE NOT PRESENT IN THE FEES COLLECTION COLUMN AGAINST A SINGLE ID AND SAME DONE FOR ALL THE IDS AT THE SAME TIME. FOLLOWING IS THE CODE THAT IS DOING FOR THE SINGLE MONTH. I WANT IS TO FOR ALL THE MONTH STARTING FROM THE DEFAULT TILL THE INPUT MONTH.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <style type="text/css">
.style1 {
	text-decoration: underline;
}
</style>
        <h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<span class="style1">STUDENTS DEFAULTOR LIST</span></h1>
<body style="background-image: url('bg.jpg')">
</head>
<body>

<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die('could not connect'.mysql_error());
}
mysql_select_db("stud",$con);

$result=mysql_query("SELECT Student_ID FROM  `fees_record` WHERE MONTH =  '$_POST[month]' AND YEAR =  '$_POST[Year]'");

$all=mysql_query("SELECT Student_ID FROM  `stu` ");

$u=0;
$uu=0;
$r=0;
$i=0;


while($row = mysql_fetch_array($all))
{
$tt[$u++]=$row['Student_ID'];
}


while($inner=mysql_fetch_array($result))
{
$kk[$r++]=$inner['Student_ID'];
}


foreach($tt as $w)
{
  $p=0;
    if($r>0)
      {
        foreach($kk as $q)
          {
	     if($w == $q)
		{
		$p=1;
		}
	  }
     }
  if($p!=1)
$array[$i++]=$w;
}


echo "<center><font size='+2'><h><b>Fees Defaultors of ".$_POST['month']." ".$_POST['Year']."</b></h3></font></center>";
echo "<br>";

echo "<center><table border='1' cellpadding='10'>";
echo "<tr><td><b>Student ID</td><td><b>Student Name</td><td><b>Amount</td></tr></b></center>";


if($i>0)
{
foreach($array as $x)
{
echo "<tr>";
echo "<td>".$x."</td>";
$res=mysql_query("SELECT * FROM  `stu` WHERE Student_ID =  '$x'");
while($row = mysql_fetch_array($res))
{
  $fe=$row['Fees'];
  $na=$row['Name'];

}

echo "<td>".$na."</td>";
echo "<td>".$fe."</td>";
//echo "<br>";
//echo "<br>";
echo "</tr>";
}
echo "</table>";
}
else 
echo "No fees defaultors";
mysql_close($con);
?>


</body>
</html>
Last edited by Benjamin on Wed Oct 12, 2011 8:40 am, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: HELP REGARDING SEARCHING BETWEEN MONTHS REQUIRED

Post by jraede »

Code: Select all

SELECT Student_ID FROM `fees_record` WHERE MONTH(`fees_date`) >= '$_POST[month_start]' AND YEAR(`fees_date`) >='$_POST[year_start]' AND MONTH(`fees_date`) <= '$_POST[month_end]' AND YEAR(`fees_date` <= '$_POST[year_end]'
.

Note that (a) you need to escape your data with mysql_real_escape_string - this is just a bare bones example to show you the concept, and (b) you can store your date in a DATE field without needing separate fields for month and year.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: HELP REGARDING SEARCHING BETWEEN MONTHS REQUIRED

Post by Benjamin »

Dear Sir.

Are your lowercase keys broken?

Thanks.
Post Reply