我想在给定的luggage_id中输出bid_amount列值。 以下是截图。 参考截图,例如如果luggage_id是123561,我想只获得bid_amounts 255,25和88。
我的控制器
public function bid(){
$this->load->database();
$this->load->model('Truckeraccount_model');
$data['h']=$this->Truckeraccount_model->loads();
redirect('truckeraccount_ctrl/');
}
我的模特
public function loads() {
$luggage_id = $this->session->userdata('luggage_id');
$this->db->select('*');
$this->db->from('bids');
$this->db->where('luggage_id', $luggage_id);
$query = $this->db->get('bids');
return $query;
}
我的观点
<?php
foreach ($h->result() as $row)
{
?>
Luggage: <?php echo $row->luggage_id;?><br>
Bids: $<?php echo $row->bid_amount;?>
<?php } ?>
数据被输出为单独的行。
答案 0 :(得分:0)
这样做
在控制器中
public function bid(){
$this->load->database();
$this->load->model('Truckeraccount_model');
$data['bids']=$this->Truckeraccount_model->loads();
# remove below and load view
//redirect('truckeraccount_ctrl/');
$this->load->view('name', $data);
}
在模型中
public function loads() {
$luggage_id = $this->session->userdata('luggage_id');
$this->db->select('*');
$this->db->from('bids');
$this->db->where('luggage_id', $luggage_id);
$query = $this->db->get('bids');
$result = $query->result_array();
return $result;
}
在视图中
foreach ($bids as $bid) {
echo "Luggage ".$bid['luggage_id'];
echo "Bids ".$bid['bid_amount']; ;
}