首页 文章

如何传递多个数据阵列来查看Codeigniter

提问于
浏览
0

我是Codeigniter的新手,有两个小问题

1:如何传递两个表数据数组进行查看?

$data['customers']=$this->customer_model->get_all_customers(); 
        //$products['product']=$this->customer_model->get_all_categories();
        //$this->load->view("customer_view",$data);
        $product['cats']=$this->customer_model->get_all_categories(); 

         $this->loadViews("customer_view", $this->global, $data, $product);

但我收到了错误

2:我正在加入两个表来获取两个表数据,但我只得到一个表数据?

public function get_all_categories()
{

/*// Get Data from Two tables
$this->db->select('*');
$this->db->from('category');
$this->db->join('customers','customers.categoryID=category.categoryID','Inner');
$query=$this->db->get();

请帮我解决 .

3 回答

  • 0

    这个 :

    $query=$this->db->get();
    

    应该 :

    $query=$this->db->get()->result_array();
    
  • 0
    • 如何传递两个表数据数组来查看:

    您可以创建一个二维数组,其中位置$ data ['costumers']从get_all_costumers()接收数据,位置$ data ['cats']从get_all_categories接收数据,然后将$ data传递给您的视图 . 这将是:

    $data['costumers'][] = $this->customer_model->get_all_customers();
    $data['cats'][] = $this->customer_model->get_all_categories();
    $this->load->view("costumer_view", $data);
    

    只是提醒一下,在您看来,您将像$ cats或$ costumers一样访问它们 .

  • 0

    以下是传递多变量进行查看的解决方案

    Controller

    $data['customers']=$this->customer_model->get_all_customers(); 
    $data['cats']=$this->customer_model->get_all_categories(); 
    
    
    $data ['customers'] = $customers;
            $data ['cats'] = $categories;
        $this->loadViews("customer_view", $this->global,  $data);
    

    在视图中,我们将使用$ customers和$ categories

相关问题