dongzhiyong8577 2017-01-03 15:45
浏览 25

Codeigniter将数据从数据库显示到文本框中

I created an accounts page wherein I can view all accounts from the database. Each of them has an action button called View More. If I press View More, additional details from the database will be displayed in textboxes. I want to get the ID for each of the row and pass it to the controller in order for it to be viewed. However, I can't seem to make them show in the boxes.

Expected: Image

Current: Image

Controller:

function viewmore()
{
    $userid = $this->input->get('userid', TRUE);
    $data['view'] = $this->model_accounts->viewmore_user($userid);
    $data['main_content'] = 'view_adminviewmore';
    $this->load->view('includes/admin_viewmore_template', $data);
}

Model:

public function viewmore_user($userid)
{
     $query= $this->db->select('*')->from('accounts')->where('userid', $userid)->get();
     return $query->result();
}

View for the Action Button:

          <?php foreach($users as $row): ?>
          <tr>
              <td><?php echo $row->firstname; ?></td>
              <td><?php echo $row->lastname; ?></td>
              <td><?php echo $row->username; ?></td>
              <td><?php echo $row->address; ?></td>
              <td class="action-button mobile-important">
                <a href="<?php echo base_url() ."admin_accounts/viewmore/?id=". $row->userid ?>"> <button type="button" class="btn btn-custom-3">View More</button></a>
              </td>

          <?php endforeach; ?>
          </tr>

View for displaying the data:

<?php foreach($view as $row): ?>
     <br>
     <p> First Name </p>
     <input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->firstname; ?>">
     <br>
     <p> Last Name </p>
     <input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->lastname; ?>">
     <br>
     <p> Username </p>
     <input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->username; ?>">
     <br>
     <p> Address </p>
     <input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->address; ?>">
     <br>
     <p> E-mail Address </p>
     <input class="form-control" id="sel1" type="email" placeholder="" value="<?php echo $row->email; ?>">
     <br>
     <p> Contact Number </p>
     <input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->contactnum; ?>">
     <br>
<?php endforeach; ?>
  • 写回答

2条回答 默认 最新

  • duandaijian1583 2017-01-03 15:56
    关注

    If you are using CodeIgniter, why not use the Form Helper?

    You can use code like this:

    <?php echo form_input('sel1', $row->firstname); ?>
    

    instead of:

    <input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->firstname; ?>">
    

    Read some more about it here: https://www.codeigniter.com/user_guide/helpers/form_helper.html

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)