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."'";
4

4 回答 4

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);
于 2012-10-19T17:41:59.637 回答
1

改变

$_SESSION['SESS_MAIN_BASE']

{$_SESSION['SESS_MAIN_BASE']}

$_SESSION 变为空白,因为 [] 是一个字符串。

于 2012-10-19T17:42:18.260 回答
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."'";
于 2012-10-19T17:42:09.713 回答
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'";
于 2012-10-19T17:42:41.587 回答