Reputation:
So I'm in the middle of creating an E-Commerce site for a class. On my Profile page I'm planning to display various info stored in the db. Right now I'm only messing with the user photo. I have a function in the model that gets the Users photo from the column 'Image_Path' in DB 'users'. My problem is that for each profile view it shows the same photo. I think its return the whole array of pictures and maybe just sets it as the first one?
here is the model
<?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
?>
The Controller
<?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
The View
<!DOCTYPE html>
<html>
<head>
<title><?php echo $_SESSION['logged_in']?></title>
<style type="text/css">
.container {
width: 15%;
text-align: center;
clear:both;
}
.container input {
width: 100%;
clear: both;
}
.logout {
position: fixed;
bottom: 10%;
right: 10%;
}
.aboutme{
position:fixed;
right:50%;
bottom:50%;
}
.shopbutton{
position:fixed;
right:17%;
top:10%;
}
.checkout{
position:fixed;
right:10%;
top:10%;
}
</style>
</head>
<body>
<h3>Logged In As: <?php echo $_SESSION['logged_in']?> </h3>
**where the picture is displayed
<?php foreach ($profilepicture as $row)
{
echo '<img src='.base_url().'../'.$row->Image_Path.' style="Height: 300px; Width:200px;"><br>';
} ?>
<form action=" <?php echo base_url().'Profile';?>" method='post'>
<input type='submit' value='Upload Picture'>
</form>
<div class = 'aboutme'>
<p>About Me</p>
</div>
<div class = 'logout'>
<form action= '<?php echo base_url().'Profile/logout';?>' method='post'>
<input type="submit" value="Log Out">
</form>
</div>
<div class = 'checkout'>
<form action = '<?php echo base_url().'Cart/display_cart';?>' method='post'>
<input type='submit' value='Check Out'>
</form>
</div>
<div class = 'shopbutton'>
<form action = '<?php echo base_url().'Product/display_products';?>' method='post'>
<input type='submit' value='Shop'>
</form>
</div>
</body>
</html>
Upvotes: 0
Views: 79
Reputation:
Changed my Model function to:
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();
}//end get_single_profile
And My Controller Index To:
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
in the model I changed the Username from the table and set it to $id, In the controller I used a previously defined session variable to set $id to the session...I think
Upvotes: 1
Reputation: 2154
First, try changing the select portion of your query. It should be like:
$this->db->select('Image_Path, Username');
if it still not working, try to echo your last query in get_single_profile()
echo $this->db->last_query();
exit;
Upvotes: 2