Problems when populating selection box in Grid

Hello again all,

I’m having a problem when I try to populate a grid selection box from the db.

I read this tutorial [url]Start DHTMLX Docs

And set my code up as follows

$form_conn = new GridConnector($conn, "MySQL");
$form_conn->enable_log("../connLogs/areaPrefGridConLog.txt");

 //create a new options connector to populate the prefrence level selection box
$options = new OptionsConnector($conn);
$options->enable_log("../connLogs/areaPrefSelGridConLog.txt");

$options->render_table("preference_level","Preference_Level",
        "Preference_Level,Preference_Description");

// connect the options returned to the correct coloumn in the grid
$form_conn ->set_options("Preference_Level",$options);

// get the users id and use it to render there selected area preferences
$form_conn->render_sql("SELECT lpost_code_prefix.Area_Name,
                        lpost_code_prefix.Area_Code,
                        area_preferences.Preference_Level
                        FROM lpost_code_prefix,area_preferences 
                        WHERE area_preferences.Area_Code = lpost_code_prefix.Area_Code
                        AND area_preferences.User_id = $id",
                        "Area_Code",
                        "Area_Code,Area_Name,Preference_Level");

?>

I noticed that the wrong data was showing in boxes so I checked the log for the connector and found the following:

[b]
A session had already been started - ignoring session_start() at C:\wamp\www\codebase\connector\xss_filter.php line 178

SELECT Preference_Level,Preference_Level,Preference_Description FROM preference_level

SELECT lpost_code_prefix.Area_Name,
lpost_code_prefix.Area_Code,
area_preferences.Preference_Level FROM lpost_code_prefix,area_preferences
WHERE ( area_preferences.Area_Code = lpost_code_prefix.Area_Code
AND area_preferences.User_id = 2)

Done in 0.0085852146148682s
[/b]

Basically its running the correct query and then running the grid connectors render_sql() query as well and some how overwriting the results.

Where am I going wrong? I’ve tried giving each connector its own DB connection but its made no difference.
I’ve also tried just passing set_options() just an associative array as shown in the tutorial, when I do this I get nothing in the selection boxes and and I’v tried alternating the order in which the functions are called, no difference I’m stumped!

Can anyone help ?, Thanks in advance.

Ok this is getting really strange,

The connect queries are just adding there own statements !?
I’v just attempted to do a standard render_SQL () to fill a form and nothing happened heres the code:

$grid_conn->render_SQL("SELECT student.Student_No,student.Surname,student.Forename,
                          student.Email,student.Personal_Email, 
                          student.Home_Phone_No,student.Work_Phone_No,
                          student.Mobile_Phone_No,student.Address_Line_1,
                          student.Address_Line_2,student.Address_Line_3,
                          student.Address_Line_4,student.Post_Code,placement.Placement_ID
                          FROM student,placement
                          WHERE  student.Student_No = $user_Id 
                          AND placement.Student_No = student.Student_No","student.Student_No",
"Student_No,Surname,Forename,Email,Personal_Email,Home_Phone_No,Work_Phone_No
 ,Mobile_Phone_No,Address_Line_1,Address_Line_2,Address_Line_3,Address_Line_4,
 Post_Code,Placement_ID");

Now I know for a fact that when used out side the render_sql() function this query works perfectly.

However when I check the connector log I get:

[b]
A session had already been started - ignoring session_start() at C:\wamp\www\codebase\connector\xss_filter.php line 178

SELECT student.Student_No,student.Surname,student.Forename,
student.Email,student.Personal_Email,
student.Home_Phone_No,student.Work_Phone_No,
student.Mobile_Phone_No,student.Address_Line_1,
student.Address_Line_2,student.Address_Line_3,
student.Address_Line_4,student.Post_Code,
placement.Placement_ID FROM student,placement WHERE ( student.Student_No = 2
AND placement.Student_No = student.Student_No) AND student.Student_No = ‘1 // this is nothing to do with me’
[/b]

I know I must be doing something wrong but I can for the life of me see what, some help would be really apprciated.

a) try to change code as

$options->render_table(“preference_level”,“Preference_Level”,“Preference_Level(value),Preference_Description(label)”);

b) normally connector will not add any extra parameters, but if you have client side filters - it may add extra parameters to the url, which will force additional filtering
Also, it possible to force such filtering while url params
docs.dhtmlx.com/doku.php?id=dhtm … filtration

Hi again,

Thanks for the response Stanislav, in answer to your question for part a I have already tried this and it has made no diffrence.

The log for my connector looks like this:

[b]
A session had already been started - ignoring session_start() at C:\wamp\www\codebase\connector\xss_filter.php line 178

SELECT Preference_Level,Preference_Level as value,Preference_Description as label FROM Preference_Level

SELECT lpost_code_prefix.Area_Name,
lpost_code_prefix.Area_Code,
area_preferences.Preference_Level FROM lpost_code_prefix,area_preferences WHERE ( area_preferences.Area_Code = lpost_code_prefix.Area_Code
AND area_preferences.User_id = 2)

[/b]

So it looks like the query is being generated but not properly linked to the select box,
what is being inserted is the value of the selection box used to set the value of preference level when it is first added as a record.
What Im trying to do is add a record to a grid setting it values using two selection boxes in a bound form, from there I want the user to be able to change the levels using a drop down selection box in the grid, as it stands all that is happening is that the first option of the grids selection box is being set to the orginal prefrence level in the form selection box.

In answer to b I do have some client side filltering attached to the grids, Ill try disabling it and see what happens.

Thanks again.

Sorry Iv just checked and the form that I used with the render_sql() on has no filltering of any kind attached to it its literally just a form that is poulated via a connector so it cant have anything to do with client side filters.
Interestingly if I just use render_table() everything works fine (the only problem is I cant get hold of that one extra piece of info, worst come to worst i coluld just miss it off and hope the boss does’nt notice :smiley: )

Just to be sure - you are loading form from above connector? Why in such case you are using GridConnector and not FormConnector ?

In case of Form selects can’t be loaded from the same data feed, but you can configure separate options feeds for the select and combo controls

Sorry I think I’ve confused the issue here, I think Im having two diffrent problems here that I thought may be related but maybe are not.

The first (and more important) problem is the issue with the selection boxes not being properly populated in my grids the following is the full code for the connector file


define('CONFIG_PATH', $_SERVER['DOCUMENT_ROOT'] . '/resources');
require_once (CONFIG_PATH . '/config.php');
require_once (CODEBASE_PATH . '/connector/grid_connector_v2.php');

// get the db settings for each paramter an store each in a variable
$host = $dbConfig ['dbSettings']['mysql']['host'];
$dbName = $dbConfig ['dbSettings']['mysql']['dbname'];
$userName = $dbConfig ['dbSettings']['mysql']['username'];
$pwd = $dbConfig ['dbSettings']['mysql']['password'];

// create a new connection to the database using variables from config file
$conn = mysql_connect($host, $userName, $pwd);
mysql_select_db($dbName);

// create a new GridConnector object to populate the grid with information from the database.
$grid_conn = new GridConnector($conn, "MySQL");
$grid_conn->enable_log("../connLogs/areaPrefGridConLog.txt");

$options = new OptionsConnector($conn);

$options->render_table("Preference_Level","Preference_Level","Preference_Level(value),Preference_Description(label)");
$grid_conn->set_options("Preference_Level",$options);

 if (isset($_SESSION ['ID'])){
 $id = $_SESSION ['ID'];
 }
 else {
     echo "Error while updating area preferences: No user id passed in SESSION variable";
 }

// get the users id and use it to render there selected transport preferences
$grid_conn->render_sql("SELECT transport_preferences.Transport_Type_ID,
                      transport_preferences.Preference_Level,
                      ltransport_type.Description
                      FROM transport_preferences,ltransport_type
                      WHERE transport_preferences.Transport_Type_ID =
                      ltransport_type.Transport_Type_ID
                      AND transport_preferences.User_ID = $id","transport_preferences.Transport_Type_ID",
                      "Transport_Type_ID,Description,Preference_Level");
?>

And the log file shows the following:

[b]
SELECT Preference_Level,Preference_Level as value,Preference_Description as label FROM Preference_Level

SELECT lpost_code_prefix.Area_Name,
lpost_code_prefix.Area_Code,
area_preferences.Preference_Level FROM lpost_code_prefix,area_preferences WHERE ( area_preferences.Area_Code = lpost_code_prefix.Area_Code
AND area_preferences.User_id = 2)

[/b]

The second problem is to do with the render_sql() function for one of my forms adding “AND student.Student_No = '1” to the end of everything sent to the db, ill probably post this in the Form part of the forum.

Sorry again about that.

In form case - form connector normally loads info only about one record in DB, so it is used as

myform.php?id=123

Which results in adding to the server side sql query “{id}=123” where id replaced with ID field defined in connector configuration, so it is expected scenario.
In your case it seems that you are have 2 in session but loading form connector as myform.php?id=1 - which results in controversial filtering rules.

Basically you can use something like

$_GET[id] = $_SESSION [‘ID’]; //set get param

if you want to ignore record id from the client side

Code looks valid.

a) please try to replace connector.js with the attached one
b) please confirm that both sql request are valid (especially options selecting one)
c) check code on client side, dhtmlxconnector.js must be included after dhtmlxgrid.js
connector.zip (1.53 KB)

Ok thanks Stanislav, Ill give what you suggested a try.

Hi again,

tried as you suggested and have noticed a strange change:

The log for the options connector now reads

[b]
A session had already been started - ignoring session_start() at C:\wamp\www\codebase\connector\xss_filter.php line 178

SELECT transport_preferences.Transport_Type_ID,
transport_preferences.Preference_Level,
ltransport_type.Description FROM transport_preferences,ltransport_type WHERE ( transport_preferences.Transport_Type_ID =
ltransport_type.Transport_Type_ID
AND transport_preferences.User_ID = 2)

[/b]

Where as the log for the grid connector now reads:

[b]

====================================
Log started, 05/07/2012 11:07:36

// its empty ???
[/b]

Looks like the options connector is rendering the grid contents and the grid connector is doing nothing??
I have’nt made any other changes to my code any clue cos im at a loss.