1

my controller is

if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class pickoftheday_display extends CI_Controller { public function __construct() { parent::__construct(); $this->load->library('session'); //$this->load->library('upload'); //$this->load->library('form_validation'); $this->load->helper('url'); $this->load->model('pickoftheday_display_model','',TRUE); $this->pickoftheday_display_model->get_pickoftheday_image(); $this->load->database(); } public function index() { $this->load->view('pickoftheday_display'); } public function get_pickoftheday_image() { $data['get_pick_picture']=$this->pickoftheday_display_model->get_pickoftheday_image(); } } 

model is

class pickoftheday_display_model extends CI_Model { public function __construct() { parent::__construct(); $this->load->database(); $this->load->library('encrypt'); $this->load->helper('security'); $this->load->helper('string'); $this->load->library('email'); } public function get_pickoftheday_image() { $query=$this->db->query("SELECT * FROM pick_of_the_day order by id desc "); if($query->num_rows>0) { return $query->result(); } else { return false; } } } 

view code is

 $val=array(); $link=array(); var_dump($get_pick_picture); foreach($get_pick_picture as $key) { $val[]= $key->image; $link[]= $key->link; } echo $link[0] 

how to display image in view..

3
  • what is the output you are getting now? Commented Feb 13, 2014 at 10:48
  • A PHP Error was encountered Severity: Notice Message: Undefined variable: get_pick_picture Filename: views/pickoftheday_display.php Commented Feb 13, 2014 at 10:50
  • echo '<img src="'.base_url($link[0]).'" />; Commented Feb 13, 2014 at 10:51

1 Answer 1

2
  1. You did not pass data to view file.
  2. You didn't set data to pass to view file.

In index function, you have to call

public function index() { $data['pick_picture']=$this->pickoftheday_model->get_pickoftheday_image(); $this->load->view('pickoftheday_display',$data); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.