Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从sql DB(CodeIgniter)获取单用户图片 所以我正在为一个类创建电子商务网站。在我的个人资料页面上,我计划显示数据库中存储的各种信息。现在我只是在搞乱用户的照片。我在模型中有一个函数,它从DB“Users”中的“Image\u Path”列获取用户照片。我的问题是,每个纵断面图都显示相同的照片。我认为它返回了整个图片阵列,也许只是将其设置为第一个_Php_Sql_Codeigniter_Phpmyadmin - Fatal编程技术网

Php 从sql DB(CodeIgniter)获取单用户图片 所以我正在为一个类创建电子商务网站。在我的个人资料页面上,我计划显示数据库中存储的各种信息。现在我只是在搞乱用户的照片。我在模型中有一个函数,它从DB“Users”中的“Image\u Path”列获取用户照片。我的问题是,每个纵断面图都显示相同的照片。我认为它返回了整个图片阵列,也许只是将其设置为第一个

Php 从sql DB(CodeIgniter)获取单用户图片 所以我正在为一个类创建电子商务网站。在我的个人资料页面上,我计划显示数据库中存储的各种信息。现在我只是在搞乱用户的照片。我在模型中有一个函数,它从DB“Users”中的“Image\u Path”列获取用户照片。我的问题是,每个纵断面图都显示相同的照片。我认为它返回了整个图片阵列,也许只是将其设置为第一个,php,sql,codeigniter,phpmyadmin,Php,Sql,Codeigniter,Phpmyadmin,这是模型 <?php class Profile_Model extends CI_Model { public function __construct() { $this->load->database(); } // public function get_profile_picture() // { // // $query = $this->db->get('users'); //

这是模型

<?php
class Profile_Model extends CI_Model
{

    public function __construct()
    {
      $this->load->database();
    }

 //    public function get_profile_picture()
 //    {
 //
 //      $query = $this->db->get('users');
 //      return $query -> result();
 // }
 public function get_single_profile($id){
   //get whole table

   $this->db->select('Username');
   $this->db->select('Image_Path');
   $this->db->from('users');
   $this->db->where('User_ID', $id);
   $query = $this->db->get();
return $query->result();

 }//end get_single_profile

 //for uploading profile pics
public function set_profile_pic(){

}

 }//CLASS
?>

控制器

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Profile extends CI_Controller {

public function __construct()
{

    parent::__construct();
    $this->load->helper('form');
    $this->load->helper('url');
        $this->load->library('session');    //needed to use global session variables
        $this->load->helper('language');
        $this->load->model('Profile/Profile_Model');
}

public function index()
{

    if($this->session->userdata('logged_in'))
    {

        $data['profilepicture'] = $this->Profile_Model->get_single_profile();

            $this->load->view('Profile/Profile', $data);
    }// echo session variable logged_in
    else{

        redirect( base_url().'Login');  //redirect to user profile view after verification)
    }
}//END Index
public function logout(){
    $this->session->sess_destroy();
    redirect(base_url(). 'Login');
}//END LOGOUT

public function display_profile_pic(){

    $data['profilepicture'] = $this->Profile_Model->get_profile_picture();
    $this->load->view('Product/Product', $data);


}
}//END CLASS

首先,尝试更改查询的select部分。应该是这样的:

$this->db->select('Image_Path,Username')

如果它仍然不起作用,请尝试在
get\u single\u profile()


首先,尝试更改查询的select部分。应该是这样的:

$this->db->select('Image_Path,Username')

如果它仍然不起作用,请尝试在
get\u single\u profile()


将我的型号功能更改为:

  public function get_single_profile($id){
   //get whole table


   $this->db->select('Image_Path');
   $this->db->from('users');
   $this->db->where('Username', $id);
   $query = $this->db->get();
   echo $this->db->last_query();
   return $query->result();
}//结束获取单个配置文件

我的控制器索引为:

public function index()
    {

        if($this->session->userdata('logged_in'))
        {
            $data['profilepicture'] =        $this->Profile_Model->get_single_profile($this->session->userdata('logged_in')    );

                $this->load->view('Profile/Profile', $data);
        }// echo session variable logged_in
        else{

            redirect( base_url().'Login');  //redirect to user profile     view after verification)
        }
    }//END Index

在模型中,我更改了表中的用户名并将其设置为$id,在控制器中,我使用了先前定义的会话变量将$id设置为会话…我认为

将模型函数更改为:

  public function get_single_profile($id){
   //get whole table


   $this->db->select('Image_Path');
   $this->db->from('users');
   $this->db->where('Username', $id);
   $query = $this->db->get();
   echo $this->db->last_query();
   return $query->result();
}//结束获取单个配置文件

我的控制器索引为:

public function index()
    {

        if($this->session->userdata('logged_in'))
        {
            $data['profilepicture'] =        $this->Profile_Model->get_single_profile($this->session->userdata('logged_in')    );

                $this->load->view('Profile/Profile', $data);
        }// echo session variable logged_in
        else{

            redirect( base_url().'Login');  //redirect to user profile     view after verification)
        }
    }//END Index

在模型中,我更改了表中的用户名并将其设置为$id,在控制器中,我使用先前定义的会话变量将$id设置为会话…我认为

带有退出符号时,它没有显示任何内容,但我看不到最后一次查询仅获取数据库中的第一张用户图片,当我尝试将$id变量传递给控制器时,它显示为NULL。如果我传递一个特定的用户ID,比如27,它会显示该用户行的图片;将用户id分配给$id。(我讨厌在这里评论)退出标志将终止脚本的执行。因此,如果:echo$this->db->last\u query()没有显示任何内容(它应该打印正在执行的SQL查询)那么你在下面的陈述中做错了什么$这->数据库->选择('Image_Path')$此->数据库->来自(“用户”)$这->数据库->其中('Username',$id)$query=$this->db->get();使用exit符号,它什么也不显示,但是我没有看到最后一个查询只获取数据库中的第一个用户图片,当我尝试将$id变量传递给控制器时,它显示为NULL。如果我传递一个特定的用户ID,比如27,它会显示该用户行的图片;将用户id分配给$id。(我讨厌在这里评论)退出标志将终止脚本的执行。因此,如果:echo$this->db->last\u query()没有显示任何内容(它应该打印正在执行的SQL查询)那么你在下面的陈述中做错了什么$这->数据库->选择('Image_Path')$此->数据库->来自(“用户”)$这->数据库->其中('Username',$id)$query=$this->db->get();
public function index()
    {

        if($this->session->userdata('logged_in'))
        {
            $data['profilepicture'] =        $this->Profile_Model->get_single_profile($this->session->userdata('logged_in')    );

                $this->load->view('Profile/Profile', $data);
        }// echo session variable logged_in
        else{

            redirect( base_url().'Login');  //redirect to user profile     view after verification)
        }
    }//END Index