Welcome Guest, Not a member yet? Register   Sign In
NEED to add a column to database generated table
#4

[eluser]pistolPete[/eluser]
Please use [ code ] tags in future posts!
I wouldn't use the table class but generate the table manually:

Controller:
Code:
<?php

class Customer extends Controller {

    function customers_list()
    {
        $this->load->model('customer_model');
        $data['all_customers'] = $this->customer_model->get_all();
        $this->load->view('customer_list',$data);
    }
    
    function delete($id)
    {
        //...
    }
    
    function edit($id)
    {
        //...
    }
}

Model:
Code:
<?php

class Customer_model extends Model
{    
    public function get_all()
    {            
        $query = $this->db->get('customer');
        
        if ($query->num_rows() > 0)
        {
            return $query;
        }
        else
        {
            return FALSE;
        }
    }

}

View:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Customers List&lt;/title&gt;
&lt;style type="text/css"&gt;
body {
  font: small/1.5em Verdana, Arial, Helvetica, serif;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

<h1>List of Customers</h1>
<table border="1" cellpadding="2" cellspacing="1" class="c_table">
<thead>
  <tr>
   <th>Customer ID</th>
   <th>Customer Name</th>
   <th>Owner Name</th>
   <th>Place</th>
   <th>Phone-1</th>
   <th>Phone-2</th>
   <th>Phone-3</th>
   <th>Preffered Lorry Transport</th>
   <th>Edit</th>
   <th>Delete</th>
  </tr>
</thead>
<tbody>
&lt;?php
/**
* You probably need to change the values of the fields below, e.g. $customer->id
* You need to use the same field names as in your database!
*/
foreach($all_customers->result() as $customer):
?&gt;
<tr>
   <td>&lt;?php echo $customer->id;?&gt;</td>
   <td>&lt;?php echo $customer->name;?&gt;</td>
   <td>&lt;?php echo $customer->place;?&gt;</td>
   <td>&lt;?php echo $customer->phone1;?&gt;</td>
   <td>&lt;?php echo $customer->phone2;?&gt;</td>
   <td>&lt;?php echo $customer->phone3;?&gt;</td>
   <td>&lt;?php echo $customer->lorry;?&gt;</td>
   <td>&lt;?php echo $customer->id;?&gt;</td>
   <td>&lt;?php echo site_url('customer/edit/'.$customer->id);?&gt;</td>
   <td>&lt;?php echo site_url('customer/delete/'.$customer->id);?&gt;</td>
  </tr>
&lt;?php
endforeach;
?&gt;
</tbody>
</table>

&lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
NEED to add a column to database generated table - by El Forum - 04-25-2009, 09:20 AM
NEED to add a column to database generated table - by El Forum - 04-25-2009, 09:26 AM
NEED to add a column to database generated table - by El Forum - 04-25-2009, 10:34 AM
NEED to add a column to database generated table - by El Forum - 04-25-2009, 12:58 PM
NEED to add a column to database generated table - by El Forum - 04-25-2009, 01:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB