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

[eluser]Ram2810[/eluser]
Hi everyone

I got stuck with this table generation code.
I generated a table of data generated from database ,now i need to add a column in the end with a link tag to edit the row,i need to get the this edit link auto generate as the rows of data increase.

Can anyone help please

Thank you
#2

[eluser]pistolPete[/eluser]
Post the view, model and controller code you have by now.
#3

[eluser]Ram2810[/eluser]
VIEW PAGE
--------------------------------------------------------------------

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>
&lt;?php
// this table library is autoloaded
$tmpl = array ( 'table_open'  => '<table border="1" cellpadding="2"
                 cellspacing="1" class="c_table">' );

$this->table->set_template($tmpl);
$this->table->set_heading('Customer ID','Customer Name', 'Owner Name', 'Place','Phone-1',
                          'Phone-2','Phone-3','Preffered Lorry Transport','Edit','Delete');
$query = $this->db->query("SELECT * FROM customer");

echo $this->table->generate($query);


?&gt;

&lt;/body&gt;

&lt;/html&gt;

----------------------------------------------------------
MODEL PAGE
-----------------------------------------------------------
Code:
&lt;?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Customer_model extends Model
{
    function Customer_model()
    {
        parent::Model();
    }
    
    public $data;
function select_customer()
   {

        $this->db->get('customer');

   }
}

?&gt;

-------------------------------------------------------
CONTROLLER PAGE
---------------------------------------------------------
Code:
&lt;?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

class Customer extends Controller {
    function Customer()
{
    parent::Controller();
}
  function index()
  {
    
  }
function customers_list()
  {
       $this->load->model('customer_model');
     // $query = $this->customer_model->select_customer();
      $this->load->view('customer_list');
  }
}


?&gt;

----------------------------------------------------

These are the pages i worked ............ hope some one corrects me


thank you
#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:
&lt;?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:
&lt;?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;
#5

[eluser]Dam1an[/eluser]
[quote author="pistolPete" date="1240703934"]I wouldn't use the table class but generate the table manually[/quote]

Or, if you insist on using the table class, then use th add_row fuction

You should also do all the table inititialisation in the controller, not the view




Theme © iAndrew 2016 - Forum software by © MyBB