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

Recommended Answers

All 2 Replies

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;
}

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); ?>" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.