为什么我在此字符串中出现此类错误:
$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."'";
答案 0 :(得分:8)
替换
$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);
答案 1 :(得分:1)
更改
$_SESSION['SESS_MAIN_BASE']
到
{$_SESSION['SESS_MAIN_BASE']}
$ _ SESSION变为空白,因为[]是一个字符串。
答案 2 :(得分:0)
试试这个:
$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."'";
答案 3 :(得分:0)
$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'";