1
A
回答
0
您可以通过创建对用户的模式去做。最简单的方法是使用sql join在模型中创建单个方法,但我更喜欢为不同类型的数据分离方法。
class User_model extends CI_Model {
public $User_id;
public $Lname;
public $Fname;
public $Timestamp;
public function __construct($id = null){
parent::__construct();
}
public function getUserByID($id){
$query = $this
->db
->from('Users')
->where('User_id', $id)
->get();
$results = $query->result();
if(count($result) > 0){
return $result[0];
}
}
public function getUserPicturesByID($id){
$query = $this
->db
->from('Images')
->where('User_id', $id)
->get();
$results = $query->result();
if(count($result) > 0){
return $result;
}
}
public function getAllUserDataByID($id){
$query = $this
->db
->from('Users')
->join('Images', 'Users.User_id = Images._User_id')
->where('User_id', $id)
->get();
$results = $query->result();
if(count($result) > 0){
return $result[0];
}
}
}
您可以通过添加模型名称的application/config/autoload.php文件,也可以从你的控制器负荷模型自动加载模型。
$this->load->model('User_model');
然后就可以调用模型方法在你的控制器这样
$user = $this->User_model->getUserByID(1);
$userPictures = $this->User_model->getUserPicturesByID(1);
和数据传递到这样的观点:
$data = array(
'user' => $user,
'pictures' => userPictures
);
$this->load->view('user_view', $data);
...和你的观点,你可以访问这样的数据:
echo $user->Fname;
或在foreach循环中的图片:
foreach($pic in $pictures){
echo '<img src="', $pic->ImagePath, '" />';
}
相关问题
- 1. 单个产品页面上的产品图片未显示
- 2. DNN-显示产品清单
- 3. 编辑模板bootstrap在行中显示4个产品图像
- 4. 在向导中显示产品图像
- 5. Magento - 显示个别产品
- 6. 在codeigniter中显示多行
- 7. 如何在wordpress中的单个产品页面中显示分组产品?
- 8. 在单个JOptionPane中显示多个System.out.print?
- 9. 如何在opencart的单个页面中显示所有产品?
- 10. 在QTableView的单个单元格中显示多个图标
- 11. 在mysql中显示多个产品foreach行php
- 12. WordPress的:Woocommerce简单的产品图像不显示
- 13. 如何随意在单个UIImage上显示多个图像
- 14. RecyclerView显示多个图像
- 15. 使用PHP和My SQL单击产品图像显示产品详细信息
- 16. 打开图形单个图像但显示多个
- 17. 在WPF中显示单个像素
- 18. 显示单个图像使用CakePHP
- 19. 如何显示woocommerce组产品中的儿童产品图像?
- 20. 从多图像(动画)GIF文件显示单个图像
- 21. 在java中显示多个图像
- 22. 在tabbedpane中显示多个图像
- 23. 在PrettyPhoto中显示多个图像
- 24. Magento 1.4在主页上显示单个产品
- 25. 在单个产品页面上显示自定义字段
- 26. 在Magento中显示可配置产品的简单产品清单
- 27. 产品图片未显示在我的magento愿望清单中
- 28. 如何显示显示最近的第一个产品的所有订单? Woocommerce
- 29. 单个Google表单中的多个图表不会显示
- 30. 在滑块显示中显示多个图像
感谢您的帮助@siniša-dragičević-martinčić – Alpesh