php - 如何将数据库中的数据显示到 CodeIgniter 中的输入表单
问题描述
*我想将数据库中的数据显示到输入表单,我试图搜索,但它向我显示了表格我该如何解决这个问题......错误总是显示在 foreach 行,它说未定义的变量和提供的参数无效
谢谢你.....*
该模型
class Profile_model extends CI_Model {
public function fetch_data(){
$query = $this->db->get("tbl_admin"); //select * from tbl_admin
return $query;
}
}
控制器
class Profile extends CI_Controller {
public function index()
{
$this->load->database();
$this->load->model('profile_model');
$data["fetch_data"] = $this->profile_model->fetch_data();
$this->load->view('bootstrap/dashboard/settings_modal', $data);
}
}
风景
<?php foreach ($fetch_data as $value) {
$username = $value['username'];
$email = $value['email'];
$contact = $value['contact'];
$password = $value['password'];?>
<?php $attributes = array('id'=>'login_form1', 'class'=>'form'); ?>
<?php echo form_open('profile', $attributes); ?>
<div class="form-group text-left">
<label> Username </label>
<input type="text" class="form-control" value="<?php echo $value['username']; ?>" placeholder="Enter Username" name="username" required>
</div>
<div class="form-group text-left">
<label> Email </label>
<input type="Email" class="form-control" value="<?php echo $value['email']; ?>" placeholder="Enter Email" name="email" required>
</div>
<div class="form-group text-left">
<label> Contact Number</label>
<input type="number" class="form-control" value="<?php echo $value['contact']; ?>" placeholder="Enter Contact Number" name="username" required>
</div>
<div class="form-group text-left">
<label> Password </label>
<input type="Password" class="form-control" value="<?php echo $value['password']; ?>" placeholder="Enter Password" name="password" required>
</div>
<div class="form-group text-left">
<label> Confirm Password </label>
<input type="Password" class="form-control" value="<?php echo $value['password']; ?>" placeholder="Confirm Password" name="confirm" required>
</div>
<button class="btn btn-primary float-right" type="button">Submit</button>
<?php echo form_close(); ?>
<?php } ?>
解决方案
$fetch_data 现在只是查询,您必须使用结果或行函数获取数据
<?php
foreach($fetch_data->result() as $value)
{
$username = $value->username;
//bla bla
}?>
推荐阅读
- python - 更新颜色条/颜色轴位置 - Plotly Python
- ms-access - 使用 Visual Basic 的 3 合 1 表
- java - 如何根据 Spring Boot 中的活动配置文件加载自定义属性文件
- php - 无法通过 PHP 使用 REST API 在 GitLab 中创建用户(错误:401 未授权)
- python - 我想通过 embed at ban 命令发送消息 (Discord.py)
- java - 如何在 Keycloak 用户存储提供程序中更改自定义用户属性的值后更新外部存储
- spring-boot - 如何在springboot应用程序中使用JSF任务表单部署流程
- javascript - 当所有值都为空时,Lodash sumBy 返回空
- javascript - 在 html 中使用 javascript 显示当前日期
- macos - AudioObjectAddPropertyListener 用于 framebuffersize 改变 Core Audio