为什么不能调用函数里面的变量?
<?php <br /> <br /> //定义常量<br /> define("EntTime", "2012-08-01");<br /> define("EntTime2", "2012-08-31");<br /> define("Query_field", "品号");<br /> define("Operate", "包含");<br /> define("requirement", "WDZ");<br /> <br /> //将常量转换为变量<br /> $EntTime = EntTime;<br /> $EntTime2 = EntTime2;<br /> $Query_field = Query_field;<br /> $Operate = Operate;<br /> $requirement = requirement;<br /> <br /> //自定义函数<br /> function jhRepPd(){<br /> GLOBAL $PUR,$MOC;<br /> switch($Operate){<br /> case "包含":<br /> if($Query_field=="品号"){<br /> $PUR = "PURTH.TH004 like'%".$requirement."%' AND ";<br /> }<br /> break;<br /> }<br /> }<br /> <br /> //去除日期中的"-"<br /> $a_date = "PURTG.TG003 >='".str_replace("-","",$EntTime)."'";<br /> $b_date = "PURTG.TG003 <='".str_replace("-","",$EntTime2)."'";<br /> <br /> //判断变量是否为空<br /> if(!empty($EntTime) && !empty($EntTime2) && $requirement!==""){<br /> $date = "(".$a_date." AND ".$b_date.") AND ";<br /> jhRepPd();<br /> };<br /> <br /> //sql语句<br /> $sql = "SELECT * FROM TB where {$date}{$PUR}dbId in('1','2','3')";<br /> <br /> //打印SQL语句<br /> echo $sql;<br /> <br /> ?>
--这是打印结果,但不是正确的。因为函数中的变量没有输出,为什么?<br /> SELECT * FROM TB where (PURTG.TG003 >='20120801' AND PURTG.TG003 <='20120831') AND dbId in('1','2','3')<br /> <br /> --正确的结果应该是:<br /> SELECT * FROM TB where (PURTG.TG003 >='20120801' AND PURTG.TG003 <='20120831') AND PURTH.TH004 like'%WDZ%' AND dbId in('1','2','3')