在PHP页面中,进行日期时间的查询,需要用到MySQL中函数。如果要查询指定月份的记录,形式如下所示:
<?php
$da=date("m");
$da1=date("Y");
$link=mysql_connect("localhost","root","root");
mysql_select_db("chan");
$sql="select * from xiao where MONTH(chan_date)='$da' AND YEAR(chan_date)='$da1'";
$result=mysql_query($sql);
$num = mysql_num_rows($result);
$pricenum=0;
if($num>0){
while($rs=mysql_fetch_object($result))
{
$bian=$rs->chan_id;
$name=$rs->chan_name;
$price=$rs->chan_price;
$shu=$rs->chan_shu;
$kou=$rs->chan_kou;
$pr=$rs->chan_pr;
$pricenum=$pricenum+$pr;
echo "<tr><td>".$bian."</td><td>".$name."</td><td>".$price."</td><td>".$shu."</td><td>".$kou."</td><td>".$pr."</td></tr>";
}
echo "本月总的销售额为<font color=red>".$pricenum."</font>元";
mysql_close();
}
else {
echo "<script Lanuage='JavaScript'>window.alert('今天没有销售额')</script>";
echo "<script Lanuage='JavaScript'>window.location ='index.php'</script>";
}
?>