コントローラーから2つの配列を結合するにはどうしたらいいですか?私はAND
演算子を以下のように使用しようとしましたが失敗しました。どうすればそれを可能にすることができますか?ここコントローラーから2つの配列を結合するにはどうすればいいですか
function view_product($category_id)
{
$category_id=$this->uri->segment(3);
$this->load->model('select');
$this->data["products"]=$this->select->get_products($category_id);
$this->data["prices"]=$this->select->get_price($category_id);
$this->load->view("header");
$this->load->view("products",
$this->data);
}
は、私の見解は以下のとおりです。
<?php
$n=0;
foreach(($products as $product) && ($prices as $price)) {
$n++;
echo '<tr><td>' .$n .'</td><td>'.$product['product_id'].'</a></td>
<td>'.$product['product_name'].'</td><td>'.$product['product_description'].'</td><td>'.$price['price_per_unit'].'</td><td>'.$price['price_per_item'].'</td></tr>';
}
echo '</table>';
?>
マイモデル
私は、コントローラからの二つの配列を結合するにはどうすればよいfunction get_products($category_id)
{
$this->db->select('*');
$this->db->from('categories c');
$this->db->join('products p', 'c.category_id=p.category_id', 'left');
$this->db->where('c.category_status = 0');
$this->db->where('c.category_id', $category_id);
$query = $this->db->get();
return $query->result_array();
}
function get_price($category_id)
{
$this->db->select('*');
$this->db->from('categories c');
$this->db->join('price r', 'c.category_id=r.category_id', 'c.product_id=r.product_id', 'left');
$this->db->where('c.category_status = 0');
$this->db->where('c.category_id', $category_id);
$query = $this->db->get();
return $query->result_array();
}
?
両方のアレイのデータ構造を投稿してください – Kisaragi
なぜ必要なのですか?私はあなたが '$ price'にアクセスしていることに気が付いていますが、コントローラ内で変数 'price'を' $ this-> data ["prices"] = $ this-> select-> get_price($ category_id ); ' – DFriend