|
|
 Joai - 2010-01-20 22:00:18
Hi,
I love having an editable table that uses MySql as its backend. One thing though, I'm having trouble getting the table to work with dynamically generated where clauses when the column value is dynamically generated. For example, the following code works:
$first_name= "Joy";
$options = array("defaultcols" => array("first_name" => $first_name));
$src = new drasticSrcMySQL($server, $user, $pw, $db, $table, $options);
However, the following code, which dynamically generates the column value, does not. Apparently, the $_POST does not work when it is put before the <head> tag:
$first_namet = $_POST['first_name'];
$options = array("defaultcols" => array("first_name" => $first_name));
$src = new drasticSrcMySQL($server, $user, $pw, $db, $table, $options);
I tried placing the code between the <head> tags. But then the code does not work, because the DrasticTools JavaScript writes headers, which must be written first.
I would imagine the drasticSrcMySQL object would have to be modified after it is written. I tried adding the following lines before the table is drawn, but the following did not work:
$first_name = $_POST['first_name'];
$src->defaultcols["first_name"] = $first_name;
And I also tested the code with the following, which also did not work:
$first_name = "Joy";
$src->defaultcols["first_name"] = $first_name;
Is there a way to do what I want to do? If so, can you supply the code? Plus, an example would be of most help. Thanks for your help.
 dd - 2010-01-21 09:26:44 - In reply to message 1 from Joai
Hi Joai,
That does not works because of the Ajax based communication between browser and backend. In fact, if you want the defaultcols value to be dynamic, you have to pass the value from the php to the javascript (using the addparams parameter) so that the javascript will pass the parameter to the php file where you can grab it in the code. See ExampleGrid for an example.
To help you start, here is how to call the grid sould probably look:
thegrid = new drasticGrid('grid1', {
pathimg:"img/",
pagelength:10,
addparams:"&first_name="+<?php echo $first_name?>
});
and here is a code fragment that shows how to grab the first_name in the modified drasticSrcMySQL.php code:
/* Optionally retrieve parameters from the addparams parameter.
* Uncomment the line below and change "myparameter" to the name of your parameter
* If you pass multiple parameters copy the line multiple times
*
* $myparameter = $_REQUEST["myparameter"];
*/
$first_name = $_REQUEST["first_name"];
$this->conn = mysql_connect($server, $user, $pw) or die(mysql_error());
mysql_select_db($db) or die (mysql_error());
$this->table = $table;
// Overrule first_name in defaultcols by first_name from addparams parameter:
$this->defaultcols["first_name"] = $first_name;
---
Hope this helps,
DrasticData
 Joai - 2010-01-21 19:16:16 - In reply to message 2 from dd
Thanks a bunch! It worked beautifully!
|