News:

Wondering if this will always be free?  See why free is better.

Main Menu

month dates from mysql in php

Started by mdvignesh, March 20, 2012, 07:56:29 AM

Previous topic - Next topic

mdvignesh

i want to make a monthly report

  the user selects month from drop down and i must get the specified dates of that month from the DB
  I am using ajax to get the dates

How to get the selected month records

mdvignesh

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function monreport(str) {
if (str=="") {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_report.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onChange="monreport(this.value)">
<option value="">Select</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sept</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
</form>
<br />
<div id="txtHint"></div>
</body>
</html>



<?php
$cnn 
mysql_connect("localhost","root","");
mysql_select_db("hms",$cnn);

$month=$_GET['q'];
echo 
"<strong>$month</strong> Month Report";

/*$result=mysql_query("SELECT month(date) As newd FROM 
stock_entries WHERE month(date)='".$month."' ");
*/



if(!
$result) die(mysql_error());
echo 
"<table border='1'>";

while(
$row mysql_fetch_array($result)) {
  echo 
"<tr>";
//  echo "<td>" . date("m",strtotime($row['date'])) . "</td>";
  
echo "<td>" $row['date'] . "</td>";
  echo 
"<td>" $row[7] . "</td>";
  
//echo "<td>" . $row[''] . "</td>";
  //echo "<td>" . $row[''] . "</td>";
  
echo "</tr>";
  }
echo 
"</table>";
?>

Advertisement: