这是我的profile.php代码,我想在网页中显示它
<!-- Bridegroom Profile Details -->
<div class="w3ls-list">
<div class="container">
<h2>Bridegroom Profile Details</h2>
<div class="col-md-9 profiles-list-agileits">
<div class="single_w3_profile">
<div class="agileits_profile_image">
<?php foreach ($profile_details as $row) { ?>
<img src="<?php echo $row['upload'];?>" alt="profile image" />
<?php } ?>
</div>
<div class="clearfix"></div>
</div>
<div class="profile_w3layouts_details">
<div class="agileits_aboutme">
<h4>Profile</h4>
<h5>Personal Details:</h5>
<div class="form_but1">
<label class="col-sm-3 control-label1" for="Relation">Profile for : </label>
<div class="col-sm-9 w3_details">
<!--Brother-->
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-3 control-label1" for="Relation">Name : </label>
<div class="col-sm-9 w3_details">
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-3 control-label1" for="Relation">Gender : </label>
<div class="col-sm-9 w3_details">
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-3 control-label1" for="Relation">Dob : </label>
<div class="col-sm-9 w3_details">
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-3 control-label1" for="Relation">Religion : </label>
<div class="col-sm-9 w3_details">
</div>
<div class="clearfix"> </div>
</div>
<div class="form_but1">
<label class="col-sm-3 control-label1" for="Relation">Mobile : </label>
<div class="col-sm-9 w3_details">
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
</div>
</div>
</div>
这是我的控制器home.php 请帮助您了解如何显示此个人资料
public function profile($param1='')
{
//$data['user_detail'] = $this->db->get_where('admin',array('id'=> $this->session->userdata('admin_id')))->result_array();
$data['page_name']='profile';
$data['profile_details']=$this->db->get_where('profile',array('id' => $param1))->result_array();
$this->load->view('index',$data);
}
答案 0 :(得分:0)
因为你已经知道这样做了
<?php foreach ($profile_details as $row) { ?>
<img src="<?php echo $row['upload'];?>" alt="profile image" />
<?php } ?>
我觉得你想做的就像下面的那样?
<div class="form_but1">
<label class="col-sm-3 control-label1" for="Relation">Name : </label>
<div class="col-sm-9 w3_details">
<?php echo $row['Name'];?> // or the name of the column
</div>
<div class="clearfix"> </div>
</div>
在数据库查询后放置print_r($data)
并检查是否确实得到了结果。
public function profile($param1='')
{
//$data['user_detail'] = $this->db->get_where('admin',array('id'=> $this->session->userdata('admin_id')))->result_array();
$data['page_name']='profile';
$data['profile_details']=$this->db->get_where('profile',array('id' => $param1))->result_array();
print_r($data);
$this->load->view('index',$data);
}
答案 1 :(得分:0)
由于您提取single record
所以此处不需要foreach
这样简单
<?php if(isset($profile_details[0]['upload'])) { ?>
<img src="<?php echo $profile_details[0]['upload'];?>" alt="profile image" >
<?php } ?>
和
<div class="form_but1">
<label class="col-sm-3 control-label1" for="Relation">Name : </label>
<div class="col-sm-9 w3_details">
<?php if(isset($profile_details[0]['Name'])) {
echo $profile_details[0]['Name'];
} ?>
</div>
<div class="clearfix"> </div>
</div>
答案 2 :(得分:0)
正确获取视图中的数据或在CodeIgniter中的页面中显示数据:
如果您知道要提取单个记录,请使用row_array
而不是result_array
。仅当您知道从数据库中获取多行时才使用result_array
。
你的模特:
public function get_single_profile($param1)
{
$query = $this->db
->select('*')
->where('id', $param1)
->get('profile');
$profile_data = $query->row_array();
return $profile_data;
}
在控制器中:
在__construct
public function profile($param1)
{
$this->load->model ('your_model');
$profile_data = $this->your_model->get_single_profile ($param1);
$this->load->view ('index',['profile_data' => $profile_data]);
}
在视图页面上:
<?php if(isset($profile_data) && !empty($profile_data)){ ?>
<img src="<?php echo $profile_data['upload'];?>" alt="profile image" />
//And So on...
<?php } ?>