1

How do I get an image stored in a field of my database, and put it into a variable for using it in an email message like a signature?

Here is my code:

//Model user_model

function getImage(){
  $this->db->select("image");
  $this->db->where("$id", user_id);
  $query = $this->db->get("users");

    if($query->num_rows()>0){
      return result();
    }else{
      return false;
    }  

}

//Controller user_controller

  function image(){
    this->load->model("user_model");

    $id = $this->session->userdata('id');

    $image = $this->user_model->getImage($id);

    echo $image;
  }
2
  • Welcome to Stack Overflow. Please review How do I ask a good question. Your question should include a clear outline of your specific coding-related issue, a summary of what you have already tried and the relevant code in a Minimal, Complete, and Verifiable example, so we have enough information to be able to help. Commented Sep 20, 2017 at 20:23
  • edited complete Commented Sep 21, 2017 at 12:30

1 Answer 1

1

Here is a example

Model user_model

// Pass the id function 

function getImage($id){
    $this->db->where($id, 'user_id');
    $query = $this->db->get("users");

    if($query->num_rows()>0){
      return $query->row_array();
    }else{
      return false;
    }  

}

Controller user_controller

function image(){
  $this->load->model("user_model");

  $somedata = $this->user_model->getImage($this->session->userdata('id'));

  $data['image'] = $somedata['image'];

  $this->load->view('someview', $data);
}

On view

<?php echo $image;?>
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for your answer, i was trying make it work, but when i call $data['image'] in the view i get the error "Undefined variable: data", i'm using <?php echo $data['image']; ?> for make the call, any idea for fix this error? Thank you again!!
@AlvaroVergara I have updated it your way incorrect you should read the user guide fully

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.