• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to display data from the db in html tables dynamically?

#1
[eluser]towki[/eluser]
how could I display my data from the database to a html table dynamically?
Because I dont want to create manually each row in a table, i mean for each rows of data a table for it should be automatically created
Please give me examples on how to do this. Please use example first name and last name data

#2
[eluser]theprodigy[/eluser]
You can pass your query results directly to the generate function of the table class.

HTML Table class

#3
[eluser]InsiteFX[/eluser]
Code by Adam Griffiths Auth 1.0.6
Code:
// --------------------------------------------------------------------

/**
  * manage()
  *
  * Description:
  *
  * @access public
  * @param string
  * @return void
  */
public function manage()
{
  // Grab an array of users from the database
  $data = $this->users->users();

  // Setting headings for the table
  $this->table->set_heading('Username', 'Email', 'Actions');
  
  foreach($data as $value => $key)
  {
   // Build actions links
   $actions = anchor("admin/users/edit/".$key['id']."/", "Edit") . anchor("admin/users/delete/".$key['id']."/", "Delete");

   // Adding row to table
   $this->table->add_row($key['username'], $key['email'], $actions);
  }

  // Load the Auth specific view
  $this->auth->view('users/manage');
}

Should show you how to do it.

#4
[eluser]towki[/eluser]
[quote author="theprodigy" date="1344152817"]You can pass your query results directly to the generate function of the table class.

HTML Table class[/quote]

But can I do it without using the table class?How? please give me some examples

#5
[eluser]InsiteFX[/eluser]
Yes, but then you willneed to build your table using html and loop through it using a foresch loop

#6
[eluser]towki[/eluser]
Im really confused how to create dynamic tables...Please give me examples with the MVC pattern, because im also confused where to put or create the table, whether it should be in the model or the view.. just a simple example just to understand the logic here and some of the codes for the table class(Im gonna use the table class).Please anyone help me

#7
[eluser]theprodigy[/eluser]
There are several examples given in the link I gave you. Are those not enough?

#8
[eluser]towki[/eluser]
[quote author="theprodigy" date="1344222522"]There are several examples given in the link I gave you. Are those not enough?[/quote]

Im confused in the examples, i dont know where to put those code in the model or the controller, and how they link together, where to load the table library class...

#9
[eluser]theprodigy[/eluser]
Personally, I don't use the table class, but if I did, I would do something like:

controller
Code:
$this->load->library('table');

$records = $this->my_model->getSomething();

$data['table'] = $this->table->generate($records);

$this->load->view('myview', $data);

view
Code:
<!--
stuff above
-->
<?php echo $table; ?>
<!--
stuff below
-->

#10
[eluser]towki[/eluser]
[quote author="theprodigy" date="1344227722"]Personally, I don't use the table class, but if I did, I would do something like:

controller
Code:
$this->load->library('table');

$records = $this->my_model->getSomething();

$data['table'] = $this->table->generate($records);

$this->load->view('myview', $data);

view
Code:
<!--
stuff above
-->
<?php echo $table; ?>
<!--
stuff below
-->
[/quote]

thanks. I got the idea now.. but could you give me examples on generating a table for all of my columns in the database except for the ID column only. Normally I would use the SELECT ALL query but i dont want the id of the person to be displayed in the generated html table. sorry if my english was confusing??


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.