How could i select all column from table in datatables editor?
How could i select all column from table in datatables editor?
Aarti Sharma
Posts: 8Questions: 5Answers: 0
I want to retrieve all column of a table as i am creating columns dynamically .
Editor::inst( $db,$table,'ITEM' )
->fields(
Field::inst( 'name' )..//instead if filling field name here want to retrieve all fields of table
)
->process( $_POST )
->json();
please help me if anyone have solution for that.
Thanks in advance
This discussion has been closed.
Answers
Editor doesn't support that out of the box I'm afraid, but it is something that you can programmatically do using the API. The way to approach this is to execute a
SHOW TABLE
SQL command to get information about the table - you would then loop over the columns in the table and add aField::inst()
for each one.The downside to that approach is that it is more difficult to control validation of data. For example if you have a column for e-mail addresses it would be stored as plain text. You would need to find a way to add an e-mail address validator to it - possibly through the column name or possibly having another lookup table.
Allan
That will work for editor also?
i am using for loop but its not allowing me to use it.
Error is:
Parse error: syntax error, unexpected 'foreach' (T_FOREACH)
Wrong post. Sorry.
Yes, the PHP being used there isn't valid. What you would do is something like:
Allan