Php 在codeigniter3.0.0中从模型到控制器选择单个列
我对codeigniter是新手。 我只需要模型中的可用列,而不需要控制器中编写的代码来获得单个列 我的型号代码是:Php 在codeigniter3.0.0中从模型到控制器选择单个列,php,database,codeigniter,Php,Database,Codeigniter,我对codeigniter是新手。 我只需要模型中的可用列,而不需要控制器中编写的代码来获得单个列 我的型号代码是: public function check_reservation($restaurant_id,$date,$people,$start_time,$end_time){ $sql="SELECT r.restaurant_id,r.restaurant_name,r.capacity,rs.start_time,rs.end_time,rs.peop
public function check_reservation($restaurant_id,$date,$people,$start_time,$end_time){
$sql="SELECT
r.restaurant_id,r.restaurant_name,r.capacity,rs.start_time,rs.end_time,rs.people,rs.date,r.capacity - SUM(IFNULL(rs.people,0)) AS available FROM restaurant r
LEFT JOIN reservation rs ON r.restaurant_id = rs.restaurant_id
AND ".$date." = rs.`date`
AND ".$people." = rs.`people`
AND '".$start_time."' = rs.`start_time`
AND '".$end_time."' = rs.`end_time`
WHERE r.restaurant_id = ".$restaurant_id."
GROUP BY r.`restaurant_id`";
$query=$this->db->query($sql);
return $query->result();
}
谢谢不清楚您需要什么。如果您只想在控制器中获得一列,当您使用foreach(或for)进行迭代时,您需要输入列名
foreach ( $records as $record ) {
echo $record['restaurant_name'];
echo "<br/>";
}
foreach($records作为$record){
echo$record[“餐厅名称”];
回声“
”;
}