0

its my model

<?php

class Books_model extends CI_Model{

    public function __construct(){

        $this->load->database();

    }


    public function get_restaurants()
    {
        $sql = "SELECT id, names FROM restaurants ";
        $query = $this->db->query( $sql );
        return $query->result();

    }

}

and controller code is



<?php

class Booking_Controller extends CI_Controller{

        public function __construct(){
            parent::__construct();
            $this->load->model('Books_model');
        }
    public function view()
    {
        $this->user_data['result']=$this->Books_model->get_restaurants();

        $this->load->helper(array('form','url'));
        $this->load->view('restaurants/booking',$this->user_data);
    }
}

Plz guide me what code I written in view file that the data come in text field.....thanx

3
Contributors
2
Replies
19
Views
2 Years
Discussion Span
Last Post by gabrielcastillo
0

The model is returning an object, which is passed to $this->user_data array with the index key result so, in the view file write:

foreach($result as $row)
{
    echo $row->id . ' ' .  $row->names;
}
0

Like @cereal said you need to interate the array of data, then, if you would like to set the value of an input field, you would use. set_value('name of input field', return data)

<input id="" class="" name="book_name" value="<?php echo set_value('book_name', $row->book_name); ?>" />
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.