问题描述
我在做一个简单的请假系统,进入页面就是所有请假记录列成的表,我现在想在页面首行加入一个按人名和科室查询的输入文本框,我现在写完的代码,总提示我$sql未定义,各位能给我指点下么?下面是我这个页面的代码,后面js的代码可以不用看,那个是我为了实现正倒序排序的代码。<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/><title>干部请假信息查询</title><style>*{font-family:Arial,Helvetica,sans-serif;font-size:14px;}/*body{text-align:center;}*/table{margin:100pxauto;}td{height:25px;text-align:center;line-height:25px;border:1pxsolidsilver;}/*td{width:180px;height:25px;text-align:center;line-height:25px;border:1pxsolidsilver;}*/.red{color:red;}.top{background:#EEE;cursor:pointer;}.up{background:#FFFFCC;}.down{background:#FFFFCC;}.hov{background:#F0EFE5;}</style><?php$host='localhost';$user_name='root';$password='';$conn=mysql_connect($host,$user_name,$password);if(!$conn){die('数据库连接失败:'.mysql_error());}mysql_select_db('leave_list');mysql_query('setnamesgbk');//$station=$_POST['station'];//$worker_name=$_POST['worker_name'];//$sql1="SELECT*FROM`leave_leader`";//$sql2="ORDERBYstationASC,worker_nameASC,leave_reason,leave_dateDESC";if($station=""&&$worker_name=""){$sql="SELECT*FROM`leave_leader`ORDERBYstationASC,worker_nameASC,leave_reason,leave_dateDESC";}if($station!=""&&$worker_name=""){$sql="SELECT*FROM`leave_leader`WHERE`station`=".$station."ORDERBYstationASC,worker_nameASC,leave_reason,leave_dateDESC";}if($station=""&&$worker_name!=""){$sql="SELECT*FROM`leave_leader`WHERE`worker_name`=".$worker_name."ORDERBYstationASC,worker_nameASC,leave_reason,leave_dateDESC";}if($station!=""&&$worker_name!=""){$sql="SELECT*FROM`leave_leader`WHERE`station`=".$station."AND`worker_name`=".$worker_name."ORDERBYstationASC,worker_nameASC,leave_reason,leave_dateDESC";}//$sql="SELECT*FROM`leave_leader`ORDERBYstationASC,worker_nameASC,leave_reason,leave_dateDESC";?></head><body><?phpecho'<ahref="write.php"align="left">请假申请</a>';?><formname="chaxun"method="post"action="form1.php">车站(科室):<inputtype="text"name="$_POST[station]"> 姓名:<inputtype="text"name="$_POST[worker_name]"> <inputtype="submit"value="查询"/></form><tablecellpadding="0"id="table12"><trclass="top"><td>请假日期</td><td>车站</td><td>姓名</td><td>职务</td><td>假期开始时间</td><td>假期结束时间</td><td>请假事由</td><td>假期时长</td><td>审批人</td></tr><?php$result=mysql_query($sql);$num=mysql_num_rows($result);while($row=mysql_fetch_array($result)){?><trbgcolor="#FFFFFF"><tdwidth="140px"align="right"><?phpecho$row['leave_date'];?> </td><tdwidth="80px"align="right"><?phpecho$row['station'];?> </td><tdwidth="80px"align="right"><?phpecho$row['worker_name'];?> </td><tdwidth="80px"align="right"><?phpecho$row['job'];?> </td><tdwidth="140px"align="right"><?phpecho$row['start_time'];?> </td><tdwidth="140px"align="right"><?phpecho$row['end_time'];?> </td><tdwidth="80px"align="right"><?phpecho$row['leave_reason'];?> </td><tdwidth="80px"align="right"><?phpecho$row['leave_days'];?> </td><tdwidth="80px"align="right"><?phpecho$row['approval'];?> </td></tr><?php}mysql_close($conn);?></table><scripttype="text/javascript">vartableSort=function(){this.initialize.apply(this,arguments);}tableSort.prototype={initialize:function(tableId,clickRow,startRow,endRow,classUp,classDown,selectClass){this.Table=document.getElementById(tableId);this.rows=this.Table.rows;//所有行this.Tags=this.rows[clickRow-1].cells;//标签tdthis.up=classUp;this.down=classDown;this.startRow=startRow;this.selectClass=selectClass;this.endRow=(endRow==99999?this.rows.length:endRow);this.T2Arr=this._td2Array();//受影响的td二维数组this.setShow();},//标签切换setShow:function(){vardefaultClass=this.Tags[0].className;for(varTag,i=0;Tag=this.Tags[i];i++){Tag.index=i;addEventListener(Tag,'click',Bind(Tag,statu));}var_this=this;varturn=0;functionstatu(){for(vari=0;i<_this.Tags.length;i++){_this.Tags[i].className=defaultClass;}if(turn==0){addClass(this,_this.down)_this.startArray(0,this.index);turn=1;}else{addClass(this,_this.up)_this.startArray(1,this.index);turn=0;}}},//选中列样式colClassSet:function(num,cla){//得到关联到的tdfor(vari=(this.startRow-1);i<(this.endRow);i++){for(varn=0;n<this.rows[i].cells.length;n++){removeClass(this.rows[i].cells[n],cla);}addClass(this.rows[i].cells[num],cla);}},//开始排序num根据第几列排序aord逆序还是顺序startArray:function(aord,num){varafterSort=this.sortMethod(this.T2Arr,aord,num);//排序后的二维数组传到排序方法中去this.array2Td(num,afterSort);//输出},//将受影响的行和列转换成二维数组_td2Array:function(){vararr=[];for(vari=(this.startRow-1),l=0;i<(this.endRow);i++,l++){arr[l]=[];for(varn=0;n<this.rows[i].cells.length;n++){arr[l].push(this.rows[i].cells[n].innerHTML);}}returnarr;},//根据排序后的二维数组来输出相应的行和列的innerHTMLarray2Td:function(num,arr){this.colClassSet(num,this.selectClass);for(vari=(this.startRow-1),l=0;i<(this.endRow);i++,l++){for(varn=0;n<this.Tags.length;n++){this.rows[i].cells[n].innerHTML=arr[l][n];}}},//传进来一个二维数组,根据二维数组的子项中的w项排序,再返回排序后的二维数组sortMethod:function(arr,aord,w){//vareffectCol=this.getColByNum(whichCol);arr.sort(function(a,b){x=killHTML(a[w]);y=killHTML(b[w]);x=x.replace(/,/g,'');y=y.replace(/,/g,'');switch(isNaN(x)){casefalse:returnNumber(x)-Number(y);break;casetrue:returnx.localeCompare(y);break;}});arr=aord==0?arr:arr.reverse();returnarr;}}functionaddEventListener(o,type,fn){if(o.attachEvent){o.attachEvent('on'+type,fn)}elseif(o.addEventListener){o.addEventListener(type,fn,false)}else{o['on'+type]=fn;}}functionhasClass(element,className){varreg=newRegExp('(\s|^)'+className+'(\s|$)');returnelement.className.match(reg);}functionaddClass(element,className){if(!this.hasClass(element,className)){element.className+=""+className;}}functionremoveClass(element,className){if(hasClass(element,className)){varreg=newRegExp('(\s|^)'+className+'(\s|$)');element.className=element.className.replace(reg,'');}}varBind=function(object,fun){returnfunction(){returnfun.apply(object,arguments);}}//去掉所有的html标记functionkillHTML(str){returnstr.replace(/<[^>]+>/g,"");}//------------------------------------------------//tableid第几行是标签行,从第几行开始排序,第几行结束排序(999表示最后)升序标签样式,降序标签样式选中列样式//注意标签行的class应该是一致的varex1=newtableSort('table12',1,2,99999,'up','down','hov');</script></body></html>
解决方案
解决方案二:
ctrl+f弹出一个框输入$sql,找到此处你的代码,看看到底有没有定义