Welcome Guest, Not a member yet? Register   Sign In
Assinging a variable to an image.
#1

[eluser]Milo[/eluser]
I am very new to CI and I am having problems signing a variable to a picture that is stored in mySQL database in BLOB data.

Here is my model code:

Code:
$query = $this->db->select('picture')
    ->from('table')
    ->where('id', 4)
    ->get('');
        
$result = $query->row();

// I want to assign result to $picture variable
$picture = $result;

Here is my controller code:

Code:
$this->load->model('user_model');
$item = $this->user_model->getpicture();
  
Header("Content-type: image/jpeg");
$picture = $item->picture;


But for some reason, It is throwing a undefined variable when I <?echo $picture?> in one of my view files. Any help would be greatly appreciated! Thank you so much in advance!
#2

[eluser]Samus[/eluser]
[quote author="Milo" date="1333951233"]I am very new to CI and I am having problems signing a variable to a picture that is stored in mySQL database in BLOB data.

Here is my model code:

Code:
$query = $this->db->select('picture')
    ->from('table')
    ->where('id', 4)
    ->get('');
        
$result = $query->row();

// I want to assign result to $picture variable
$picture = $result;

Here is my controller code:

Code:
$this->load->model('user_model');
$item = $this->user_model->getpicture();
  
Header("Content-type: image/jpeg");
$picture = $item->picture;


But for some reason, It is throwing a undefined variable when I <?echo $picture?> in one of my view files. Any help would be greatly appreciated! Thank you so much in advance![/quote]

Code:
function getpicture($id) {
$query = $this->db->select('picture')
    ->from('table')
    ->where('id', $id)
    ->get(''); // make sure you select a table
        
return $query->row();
}

controller:
Code:
$this->load->model('user_model');
$item = $this->user_model->getpicture(4);
  
Header("Content-type: image/jpeg");
$data['picture'] = $item->picture;
$this->load->view('view', $data);

view
Code:
echo $picture;




Theme © iAndrew 2016 - Forum software by © MyBB