【问题标题】:Echoing table info without showing database information CodeIgniter回显表信息而不显示数据库信息 CodeIgniter
【发布时间】:2017-09-21 08:30:07
【问题描述】:

我在 CodeIgniter 中创建了一个函数,因此我可以从 2 个不同的表中打印数据库信息,并使用数组将其显示在我的视图页面上。现在我在打印时遇到的问题是它显示了所有信息,包括行名等。

它在我的视图页面上显示如下:

Array ( [0] => Array ( [user_id] => 6 [email] => jeremy2@gmail.com [voornaam] => Jeremy [product_id] => 73 [category_id] => 3 [product_naam] => Tennisracket ) ) jeremy2@gmail.com Jeremy Tennisracket

我只想让它呼应这样的名字:

**jeremy2@gmail.com Jeremy Tennisracket**

我的查看页面:

<?php print_r($userdetail_list); 
        foreach($userdetail_list as $row)
                        {
                        ?>
                        <tr>
                            <td><?php echo $row['email'];?></td>
                            <td><?php echo $row['voornaam'];?></td>
                            <td><?php echo $row['product_naam'];?></td>
                         </tr>
       <?php } ?>

我的控制器功能:

   public function details($product_id)
 {
  //load the Product_model
  $this->load->model('Product_model');

  //call function getdata in de Product_model
  $data['userdetail_list'] = $this->Product_model->getdata();

  //get product details
  $data['product'] = $this->Product_model->get_product_details($product_id);

  //laad view
  $data['main_content'] = 'details';
  $this->load->view('details',$data);
 }

我的模型函数:

 public function getdata()
{
    $this->db->select('users.user_id,users.email,users.voornaam,products.product_id,products.category_id,products.product_naam');
    $this->db->from('users');
    $this->db->join('products','products.user_id = users.user_id');
    $query = $this->db->get();
    if($query->num_rows()>0)
    {
       return $query->result_array();
    }
}

【问题讨论】:

  • 你应该在你的视图中删除print_r($userdetail_list);

标签: php codeigniter codeigniter-3


【解决方案1】:

您有一个简单的愚蠢错误,即打印整个数组 print_r($userdetail_list); 只需删除该部分即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多