How to load a table dynamically

Dear Experts,
In documentation it mentioned that if you use ‘render_tabel(‘mytable’);’ it will show all the columns dynamically.
But it is nit working.
actually it works if you mention all the columns that you want to show.
I have 21 tables and each one has so many columns that I want to get the table name from users and show all the columns dynamically without mentioning the columns one by one.
This is a limitation.
Is there anyway to see all the columns of a table???
Maybe in php we need to add some functions to do this.

please support if there is anyway.

Thanks.
Br Beniy

It depends on DB driver. When list of fields is not defined, connector will call field_list method of db driver and will use its result.

This works for sure for MySQL driver, but it may not work for other DB drivers ( as there is no common SQL code that can be used for all SQL dialects )

Dear Stanislav,
I’m using SQl and it’s not working, Can you please guide me that how can I handle it!
Something like following will work??

$colName = mssql_num_fields($result);
for ($j=1; $j<= $colName; $j++)
{
$grid->render_table(“RL_C_ALL”, mssql_field_name ($result, $j ));
}

Please check
viewtopic.php?f=19&t=38773&p=121290#p121290

Dear Stanislav,
At first thanks a lot for your support, But I have following error that I think is related to functionality of connector:


This XML file does not appear to have any style information associated with it. The document tree is shown below.

px ********* ************* My SQL Table

CREATE TABLE Products
(ProductID int PRIMARY KEY NOT NULL,
ProductName varchar(25) NOT NULL,
Price money NULL,
ProductDescription text NULL)

INSERT Products (ProductID, ProductName, Price, ProductDescription)
VALUES (1, ‘Clamp’, 12.48, ‘Workbench clamp’)


My PHP code is:


<?php require("../../codebase/grid_connector.php"); require("../../codebase/db_sqlsrv.php"); $serverName = 'NB96\SQL'; $myDB = 'Test'; $myUser = 'sa'; $myPass ='admin'; $connectionInfo = array( "Database"=>$myDB, "UID"=>$myUser, "PWD"=>$myPass); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $grid = new GridConnector($conn,"SQLSrv"); $sql = "SELECT * FROM Products"; $stmt = sqlsrv_query($conn, $sql); if( $stmt === false) { die( print_r( sqlsrv_errors(), true)); } $names = array(); $numFields = sqlsrv_num_fields( $stmt ); while( sqlsrv_fetch( $stmt )) { for($i = 0; $i < $numFields; $i++) { $names[i] = sqlsrv_get_field($stmt, $i); } } $grid->set_config(true); $grid->dynamic_loading(10); $grid->render_table("Products", "ProductID", implode(",", $names) ); ?>

Dear Stanislav,
Thank you so much,the issue has been solved, But one more clarification if you do not mind:

the issue is “name of the identity field (optional)” in render_table.
render_table(“Table_name”, “ID”,…)

As I understood it should be “integer” I meant “int” or “PRIMARY KEY”.

But in documentation it mentioned that this is optional.The issue is in reality I donot have a unique primary keys or integer keys as ID in my tables.Because all of my tables are very old and they are being updated by other program.

How can I solve this issue? to remove this limitation of mentioning the “Id” ?!
In advance thanks for your kind support.

BR,
Beniy

I need to mention that I just want to view my tables using grid, I mean I do not want to change or update them with this dhtmlxgrid…

Sorry, Actually to complete the issue ,when I use:
$grid->render_table(“RLDEP_CELL_ALL”,“CELL”,“CELL, CGI, LAI, CI, BSIC, BSC_NAME”)

Everything is working fine but when I use:

 $grid->render_table("RLDEP_CELL_ALL","CELL",implode(",", $names));

on some tables It is not working but on some tables it is working and showing following error?!!
Is this because of Size of tables? Because in small tables It’s working!!

( ! ) Notice: Undefined variable: i in C:\wamp\www\Auto Complete\dhtmlxConnector_php_v15_120612\codebase\db_sqlsrv.php on line 30

Dears,
Thanks a lot, although I found the answer by myself :wink:
1.There was an error in db_sqlsrv.php in line30 that I deleted that function and issue has been solved.
2.And another issue was related to date format which I converted to string and the issue is solved.
Br,
Beniy