正如我写这段代码$this->setlist();
这个错误,在写这行之前我没有遇到任何错误,你能帮我解决这个吗?
public function setlist(){
$mysql = new Mysql();
$query = "SELECT * FROM student where cohortid = '$this->cohort' && programid = '$this->program && departmentid = '$this->department'";
$mysql->execute($query);
while($row = $mysql->fetch_array()){
$this->list[] = $row;
}
array_unshift($this->list, "test");
unset($this->list[0]);
}
public function display_id_firstname_and_lastname(){
*$this->setlist();*
$html = new Html();
$html->table("table table-bordered");
$html->row();
$html->column(); echo "S#"; $html->closecolumn(); $html->column(); echo "FirstName"; $html->closecolumn(); $html->column(); echo "LastName"; $html->closecolumn();
$html->closerow();
foreach($this->list as $key => $value){
$html->row();
$html->column(); echo $key; $html->closecolumn(); $html->column(); echo $value['firstname']; $html->closecolumn();
$html->column(); echo $value['lastname']; $html->closecolumn();
$html->closerow();
}
$html->closetable();
}
答案 0 :(得分:3)
首先,您错过了一个变量周围的'
。
其次,您应该使用AND
而不是&&
第三,如果你想从一个对象属性中获取值,当在双引号字符串文字中使用时,将{}
中的字段包装起来。
$query = "SELECT *
FROM student
WHERE cohortid = '{$this->cohort}'
AND programid = '{$this->program}'
AND departmentid = '{$this->department}'";