高手请进,请教个php数据处理的问题
用php和mysql实现一个病人预约就诊统计功能:
默认加载页面的时候显示所有到诊的数据,也可以输入就诊日期的期间进行搜索:
现在要实现这个功能要怎么实现,下面的代码是我现在实现的部分,可能写得不正确,请高手帮忙实现这个功能。
mysql数据表结构 CREATE TABLE `yuyue` (
`id` int(11) NOT NULL auto_increment, 'id自动编号
`fangshi` varchar(250) default NULL, ‘预约方式:分为网络和电话
`yydate` varchar(250) default NULL, ’预约日期
`djdate` varchar(250) default NULL, ’登记日期
`dzhen` int(11) default '0', ’是否到诊:0还,1是
`dzdate` varchar(250) default NULL, '到诊日期
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2333 DEFAULT CHARSET=utf8;
function.inc.php
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?php function dzdate($sql,$date1,$date2) { if( !empty($date1) && !empty($date2) ){ $sql = $sql." and `dzdate` >= '$date1' and `dzdate` <= '$date2' "; } if( !empty($date1) && empty($date2) ){ $sql = $sql." and `dzdate` = '$date1'"; } if( empty($date1) && !empty($date2) ){ $sql = $sql." and `dzdate` <= '$date2'"; } return $sql; }
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?php require_once('inc/function.inc.php'); header("Content-Type: text/html; charset=utf-8"); require_once('inc/mysql.inc.php'); $weekname=array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); ?> <script language=javascript src="images/date.js"></script> <style type="text/css"> <!-- .STYLE1 {color: #FFFFFF} .STYLE2 { color: #FF0000; font-weight: bold; } --> </style> <H1><SPAN class=action-span1>(<a href="tongji.php" style="color:#FF0000">到诊病人图表</a>) (<a href="tongji_yy.php" style="color:#9cacaf">预约病人图表</a>) (<a href="tongji_dj.php" style="color:#9cacaf">登记病人图表</a>)</SPAN> <DIV style="CLEAR: both"></DIV></H1> <div class="form-div"> <form name="searchForm" action="" id="Form" method="get"> <img height="22" alt="SEARCH" src="images/start/icon_search.gif" width="26" border="0" /> 到诊日期<span class="add2"> <input name="date1" type="text" id="date1" onfocus="setday(this)" size="15" /> - </span><span class="add2"> <input name="date2" type="text" id="date2" onfocus="setday(this)" size="15" /> </span> <input name="submit2" type="submit" class="button" value=" 搜索 " /> </form> </div> <表の幅="99%" align="center" cellpadding="3" cellpacing="1"> <みんな> <tr> <th width="20%" height="24" bgcolor="#569EAB"><span class="STYLE1">诊日期</span></th> <th width="20%" bgcolor="#569EAB"><span class="STYLE1">星期</span></th> <th width="20%" bgcolor="#569EAB"><span class="STYLE1">预约数</span></th> <th width="20%" bgcolor="#569EAB"><span class="STYLE1">到達数量</span></th> <th width="20%" bgcolor="#569EAB"><span class="STYLE1">未確認数</span></th> </tr> <?php $db = 新しい dbClass(); $date1 = GetUnixTime($_GET[date1]); $date2 = GetUnixTime($_GET[date2]); $str = "`dzhen`=1 の `yuyue` から ID を選択します"; $str = !empty($date1) ? $str.dzdate($sql,$date1,$date2) : $str; $str = $str." ID の説明で並べ替えます"; $alldz = $db->getcount($str); //$sql = "select count(*) as `num`,`yydate`,`dzdate` from `yuyue` where `dzhen`=1 "; $sql = "select count(*) as `num`,`yydate`,`dzdate` from `yuyue` where `dzhen`=1 "; $sql = !empty($date1) ? $sql.dzdate($tt,$date1,$date2) : $sql; $sql = $sql." `dzdate` でグループ化、`dzdate` で順序付け、desc"; $sql2 = "count(*) を `yuyue` から `num`,`yydate`,`dzdate` として選択します (`dzhen`=0 または `dzhen`=1) "; $sql2 = !empty($date1) ? $sql.yydate($tt,$date1,$date2) : $sql; $sql2 = $sql2." `dzdate` でグループ化し、 `dzdate` で並べ替えます。"; $result = $db->query($sql); $result2 = $db->query($sql2); while($rs = $db->fetch_array($result)){ ?> <tr bgcolor="#FFFFFF"> <td height="25" align="center"><?php echo Getriqi($rs[dzdate]);?> </td> <td height="25" align="center"><?php echo $weekname[Getw($rs[dzdate])];?></td> <td align="center"> <表の幅="100%" align="center" cellpadding="1" cellpacing="1"> <みんな> <tr align="center"> <td width="30%" bgcolor="#BBDDE5"><?php echo $rs[num]?></td> <td width="30%" bgcolor="#BBDDE5"><?php echo $rs[num]?></td> <td width="30%" bgcolor="#BBDDE5"><?php echo $rs[num]?></td> </tr></tbody></table> </td> <td align="center"> <表の幅="100%" align="center" cellpadding="1" cellpacing="1"> <みんな> <tr align="center"> <td width="30%" bgcolor="#80BDCB"><?php echo $rs[num]?></td> <td width="30%" bgcolor="#80BDCB"><?php echo $rs[num]?></td> <td width="30%" bgcolor="#80BDCB"><?php echo $rs[num]?></td> </tr></tbody></table> </td> <td align="center"> <表の幅="100%" align="center" cellpadding="1" cellpacing="1"> <みんな> <tr align="center"> <td width="30%" bgcolor="#DDEEF2"><?php echo $rs[num]?></td> <td width="30%" bgcolor="#DDEEF2"><?php echo $rs[num]?></td> <td width="30%" bgcolor="#DDEEF2"><?php echo $rs[num]?></td> </tr></tbody></table> </td> </tr> <?php }?> <tr bgcolor="#FFFFFF"> <td height="25"colspan="2" align="center"><span class="STYLE2">总数</span></td> <td height="25" align="center"> <表の幅="100%" align="center" cellpadding="1" cellpacing="1"> <みんな> <tr align="center"> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> </tr></tbody></table> </td> <td height="25" align="center"> <表の幅="100%" align="center" cellpadding="1" cellpacing="1"> <みんな> <tr align="center"> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> </tr></tbody></table> </td> <td height="25" align="center"> <表の幅="100%" align="center" cellpadding="1" cellpacing="1"> <みんな> <tr align="center"> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> <th width="30%" bgcolor="#DDEEF2"><?php echo $alldz;?> 人</strong></th> </tr></tbody></table> </td> </tr> </tbody> </テーブル> <div class="clear"></div>