Welcome Guest, Not a member yet? Register   Sign In
Table heading bug?
#1

(This post was last modified: 02-11-2018, 04:05 PM by lokkook. Edit Reason: typos )

Hi,
I'm using CI 3.1.7, and trying to use properly the table library.
I am executing a request (typically a SELECT *), and use this line to output HTML :

PHP Code:
echo $this->table->generate($textes_last); 

It successfully prints a HTML tab, with my data, by the heading row is the first set of data, and not the column titles as I expect, and as the documentation describe it.

How can I use this library without having to use "set_heading()" manually ?

Thanks a lot for your help !
Reply
#2

Hard to reply without knowing exactly what $textes_last is.
Reply
#3

@lokkook

You could approach this in many ways. One of those ways...

create a method that not only returns the data from the select statement but also returns an array of the headers as well.

i.e.
[
0 => selected data array,
1 => header array
]

Then in the controller you can take the returned results and automatically set your html headers and create your html table.
Reply
#4

(02-12-2018, 08:49 AM)dave friend Wrote: Hard to reply without knowing exactly what $textes_last is.
Hi Dave,
$texte_last is the result of a SELECT * query. The line I quote prints a well formatted table with the correct data, but without the headings.
Reply
#5

(02-12-2018, 10:23 AM)php_rocs Wrote: @lokkook

You could approach this in many ways.  One of those ways...

create a method that not only returns the data from the select statement but also returns an array of the headers as well.

i.e.
[
0 => selected data array,
1 => header array
]

Then in the controller you can take the returned results and automatically set your html headers and create your html table.

Good idea... But to be clear : so the documentation seems to be wrong about the construction of the table ? The headings are not automatically created. Am I right ?

I also found "Grocery CRUD", a library that could simplify a lot table/db manipulation.
Reply
#6

Here is an example of a table created from a database query result. The table class will automatically generate the headings based on the table names (or you can set your own headings using the


Code:
set_heading()
 
method described in the class reference below).


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

$query $this->db->query('SELECT * FROM my_table');

echo 
$this->table->generate($query); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB