亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從另一個表獲取數據并在 PHP Codeigniter 中的單個表上顯示?

如何從另一個表獲取數據并在 PHP Codeigniter 中的單個表上顯示?

PHP
holdtom 2023-09-22 16:48:28
我需要幫助,我有 2 個表“客戶”和“產品”。我想根據客戶表從產品表中獲取數據并將其整體顯示。productTableproductId     productName      productPrice1             Abc              1002             Bcd              2003             Cde              300clientTableclientId        productNameId     clientName4               2                 A5               3                 B6               1                 C我希望表格將記錄顯示為:Client Name             Product NameA                       BcdB                       CdeC                       Abc我如何使用 MVC CI 展示它們。模型class Client_model extends CI_model{    function All()    {        return $client = $this->db->get('client')->result_array();    }}控制器class Client extends CI_Controller    public function index()    {        $this->load->model('Client_model');                $invoice = $this->Client_model->All();        $data = array();        $data['client'] = $client;        $this->load->view('admin/ViewClient', $data);    }}
查看完整描述

1 回答

?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

客戶端控制器代碼:-


class Client extends CI_Controller

    public function index()

    {

        $this->load->model('Client_model');

        

        $data['clientData']  = $this->Client_model->All();

        

        

        $this->load->view('admin/ViewClient', $data);

    }

}

Client_model 型號代碼:-


class Client_model extends CI_model

{

    function All()

    {

        return $client = $this->db->get('client')->result_array();

    }

}

ViewClient 查看頁面:-


<table>

<thead>

    <tr>

        <th>S.NO</th>

        <th>client Name</th>

        <th>Product Name</th>

   </tr>

</thead>


<tbody>

<?php if(!empty($clientData)) { 

    $count=1;

foreach($clientData as $client){ 

                

?>

<tr>

    <td><?php echo $count; ?></td>

    <td><?php echo $client['clientName']; ?></td>

    <td><?php 

 $pid =  $client['productNameId'];

$pdata = $this->db->get_where('productTable',array('productId '=>$pid))->row();

echo  $pdata->productName; ?>

    </td>

    

    </tr>

     <?php $count++;

    } } 

    ?>

    </tbody>


    </table>


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號