【问题标题】:Selecting a single column from model to controller in codeigniter3.0.0在codeigniter3.0.0中从模型到控制器选择单列
【发布时间】:2015-10-23 19:33:25
【问题描述】:

我是 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.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();
}

谢谢

【问题讨论】:

    标签: php database codeigniter


    【解决方案1】:

    不清楚你需要什么。如果您只想在控制器中获取一列,当您使用 foreach(或 for)进行迭代时,您会询问您的列名。

    foreach ( $records as $record ) {
        echo $record['restaurant_name'];
        echo "<br/>";
    }
    

    【讨论】:

      猜你喜欢
      • 2013-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 2019-11-01
      • 1970-01-01
      相关资源
      最近更新 更多