Welcome Guest, Not a member yet? Register   Sign In
Trouble populating form with data from database
#1


.php   ProductsEdit_Controller.php (Size: 1.88 KB / Downloads: 127)
.php   ProductsEdit_view.php (Size: 4.1 KB / Downloads: 104)
.php   products_Model.php (Size: 3.05 KB / Downloads: 114) Hope someone can help.  I have tried everything and cannot make this work.

1) I have an html table (in a view) that is populated with records from a database.
2) When the user double-clicks on a row in the table, the view grabs the records id and passes it to a new Controller, called Edit_Controller.
3) The Edit Controller calls a view that contains a form, once the form is populated with the data, the user can change the data and click the save changes to update the data, or can click a delete button to delete the record from the database.

Problem: when I run the controller, the form appears and a row at the top of the screen with the data from the selected record.  The fields of the form will not populate.  Can anyone point me in the direction on how to solve this?
Reply
#2

ProductsEdit_Controller->get() calls $this->products_Model->get($id), but the get() method in products_Model doesn't return anything. What you want to return from the method when data is not found is largely up to you, but I would generally do something like this:

PHP Code:
   public function get($id)
 
   {
 
       $query $this->db->get_where('products', array('id' => $id));
 
       if ($query->num_rows() > 0) {
            return 
$query->row_array();
        }

        
// No data found.
        
return null;
 
   

The calls to echo in the model may allow you to see the data returned from the database query, but performing an echo from a model will usually break the layout of the page because it causes your application to start output before your views are loaded.


If you need to see the data in your model and can't wait until it's passed back to your controller and through to your view, then you should setup a debugger.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB