drv16759 2019-06-28 03:20
浏览 28
已采纳

如何在编辑页面上显示记录?

I am new in MySQL and I am using CodeIgniter. I have three tables called lead, document, and bank.

Now what I am doing is, In the lead table I am inserting the customer personal information which is unique. In the document table, I am inserting the user documents. In the bank table, I am inserting the bank records. It can be multiple.

There is no issue with insertion. I am getting the issue while fetching the data from the database.

Now table structure is

lead

id  | name   | mobile     | email  
1   | asdff  |1234567831  |asd@gmail.com
2   | kjhgg  |1231231231  |mnhg@gmail.com
3   | qwsde  |1231233212  |oiuk@gmail.com
<!--many more-->

document

doc_id  |doc_name    | doc_date  | lead_id |date_of_added
1       |asdasd      |2019-06-24 | 1       |2019-06-16 17:31:07
2       |oiuytr      |2019-06-24 | 2       |2019-06-16 17:31:07
3       |okjhyt      |2019-06-25 | 3       |2019-06-20 20:12:09
<!--many more--> 

bank

bank_id  | bankname  | lead_id |date_of_added
1        | sdasdas   | 1       |2019-06-20 11:41:34
2        | asdasdasd | 1       |2019-06-21 10:41:34
3        | asdakjkh  | 2       |2019-06-21 14:23:12
4        | qwerfgvf  | 1       |2019-06-21 23:56:25
<!--many more--> 

There is no connection between the document and the bank till now. should I connect using id?

Model

public function getconfirmLeadinfo($id){
   return  $result = $this->db->select('*')
                     ->from('lead')
                     ->join('document','lead.id=document.lead_id','LEFT')
                     ->join('bank','lead.id=bank.lead_id','LEFT')
                     ->where('lead.id',$id)
                     ->get()
                     ->result();
  }

I am getting the output is

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [name] => asdff
            [mobile] => 1234567831
            [email] => asd@gmail.com
            [doc_id] => 1
            [doc_name] => asdasd
            [doc_date] => 2019-06-24
            [lead_id] => 1
            [date_of_added] => 2019-06-16 17:31:07
            [bank_id] => 1
            [bankname] => sdasdas
            [lead_id] => 1
            [date_of_added] => 2019-06-20 11:41:34

         )
[1] => stdClass Object
        (
            [id] => 1
            [name] => asdff
            [mobile] => 1234567831
            [email] => asd@gmail.com
            [doc_id] => 1
            [doc_name] => asdasd
            [doc_date] => 2019-06-24
            [lead_id] => 1
            [date_of_added] => 2019-06-16 17:31:07
            [bank_id] => 2
            [bankname] => asdasdasd
            [lead_id] => 1
            [date_of_added] => 2019-06-21 10:41:34

         )
[2] => stdClass Object
        (
            [id] => 1
            [name] => asdff
            [mobile] => 1234567831
            [email] => asd@gmail.com
            [doc_id] => 1
            [doc_name] => asdasd
            [doc_date] => 2019-06-24
            [lead_id] => 1
            [date_of_added] => 2019-06-16 17:31:07
            [bank_id] => 4
            [bankname] => qwerfgvf
            [lead_id] => 1
            [date_of_added] => 2019-06-21 23:56:25

         )
)

Now I am on edit page and I have to display the data.

if ($post){?>
<input type="text" name="name" value="<?php echo $post->name;?>">
<input type="text" name="mobile" value="<?php echo $post->mobile;?>">
<input type="text" name="email" value="<?php echo $post->email;?>">

<input type="text" name="doc_name" value="<?php echo $post->doc_name;?>">
<input type="text" name="doc_date" value="<?php echo $post->doc_date;?>">
 how do I display my bank details here? should I use something like this
    <?php
 foreach ($result as $key => $value) {
<input type="text" name="bank[]" value="$value->bankname">
}
}?>

Would you help me out?

  • 写回答

3条回答 默认 最新

  • duankaolei2921 2019-06-28 04:23
    关注

    Use two separate query as below::

    $data = [];
    $lead = $this->db->select('*')->from('lead')->get()->row();
    $data['lead'] = $lead;
    if($lead){
      $bank = $this->db->select('*')->where('lead_id', $lead->lead_id)->from('bank')->get()->result();
    $data['bank '] = $bank ;
    }
    
    
    // you can retrive documet like bank details
    
    
    return $data
    

    Then you can pass $data to view and use lead and bank variable if it exist.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题