为什么我在此字符串中收到此类错误:
$query="SELECT Name,Lastname FROM $_SESSION['SESS_MAIN_BASE'] s,
WHERE s.FK_ID_user={$id_user}
AND DATE(s.time) BETWEEN '".$d_year1."-".$d_month1."-".$d_day1."' AND '".$d_year2."-".$d_month2."-".$d_day2."'";
代替
$query="SELECT Name,Lastname FROM $_SESSION['SESS_MAIN_BASE'] s,
和
$query="SELECT Name,Lastname FROM {$_SESSION['SESS_MAIN_BASE']} s,
更好的是
$query= "SELECT Name,Lastname FROM %s s, WHERE s.FK_ID_user= '%d' AND DATE(s.time) BETWEEN '%d-%d-%d' AND '%d-%d-%d'";
$query = sprintf($query,$_SESSION['SESS_MAIN_BASE'],$id_user,$d_year1 ,$d_month1,$d_day1,$d_year2,$d_month2,$d_day2);
改变
$_SESSION['SESS_MAIN_BASE']
到
{$_SESSION['SESS_MAIN_BASE']}
$_SESSION 变为空白,因为 [] 是一个字符串。
试试这个:
$query="SELECT Name,Lastname FROM {$_SESSION['SESS_MAIN_BASE']} s, ";
$query.="WHERE s.FK_ID_user={$id_user}";
$query.="AND DATE(s.time) BETWEEN '".$d_year1."-".$d_month1."-".$d_day1."' AND";
$query.="'".$d_year2."-".$d_month2."-".$d_day2."'";
$query="SELECT Name,Lastname FROM $_SESSION['SESS_MAIN_BASE'] s,
WHERE s.FK_ID_user=$id_user
AND DATE(s.time) BETWEEN '$d_year1-$d_month1-$d_day1' AND '$d_year2-$d_month2-$d_day2'";