Send selected row items to input fields in a grid loaded in php
I have a grid loaded on the bottom of a page using the following code (in php):
Here's the code in the included "activewidgets.php" page:
I need to keep this information in a php page because I am talking to a MSSQL database. Keeping this in mind, I need to be able to click (or double click preferably) on a row in the grid, and put the data in that row into corresponding input fields. I have been able to do it without the grid being dynamically loaded in php, but I need to be able to do it inside php. Any help would greatly be appreciated.
echo"<TABLE WIDTH='100%' HEIGHT='55%' ALIGN='left' BORDER='0' CELLPADDING='2' CELLSPACING='2' BGCOLOR='#CCDDFF'>";
echo"<TR HEIGHT='25%'>";
echo"<TD COLSPAN='4' WIDTH='100%' ALIGN='left'>";
include "activewidgets.php";
$name = "obj";
echo activewidgets_grid_load($name, $dabs_searchedcodes);
echo"</TD>";
echo"</TR>";
echo"</TABLE>";
Here's the code in the included "activewidgets.php" page:
<?php
//This function creates the javascript code to load the
//active widgets grid based on the data array sent in.
function activewidgets_grid_load($name, &$data){
//How many rows are there. We need to tell the
//grid how much data we've got.
$row_count = @mssql_num_rows($data);
//How many columns are there. We need this to
//set the column header text and to build the
//array for the data.
$column_count = @mssql_num_fields($data);
//Get all the column names and create the
//array to make the column header in the grid.
$columns = "var ".$name."_columns = [\n";
for ($i=0; $i < $column_count; $i++) {
$field = @mssql_fetch_field($data, $i);
$columns .= "\"".$field->name."\", ";
}
$columns .= "\n];\n";
//Get all the data in the rows in an array
//we will use to fill the grid.
$rows = "var ".$name."_data = [\n";
while ($result = @mssql_fetch_array($data)) {
$rows .= "[";
for ($l=0; $l < $column_count; $l++) {
$rows .= "\"".$result[$l]."\", ";
// $rows .= "\"".activewidgets_html($result[$l])."\", ";
}
$rows .= "],\n";
}
$rows .= "];\n";
//echo "rows = $rows <br>";
//Finally! We are creating the javascript code that creates and formats
//the grid. When this funciton is called from a php page using "echo",
//this javascript code executes and magically create the grid.
$html = "<"."script".">\n";
$html .= $columns;
$html .= $rows;
$html .= "try {\n";
$html .= " var $name = new Active.Controls.Grid;\n";
$html .= " $name.setRowCount($row_count);\n";
$html .= " $name.setColumnCount($column_count);\n";
$html .= " $name.setDataText(function(i, j){return ".$name."_data[i][j]});\n";
$html .= " $name.setColumnText(function(i){return ".$name."_columns[i]});\n";
$html .= " var message = function(){";
$html .= " window.status = \"Grid selection:\" + ";
$html .= " \" latest=\" + this.getSelectionProperty(\"index\") + ";
$html .= " \" full list=\" + this.getSelectionProperty(\"values\") + ";
$html .= " \" (press Ctrl- to select multiple rows).\"";
$html .= " }\n";
$html .= " document.write($name);\n";
$html .= "}\n";
$html .= "catch (error){\n";
$html .= " document.write(error.description);\n";
$html .= "}\n";
$html .= "</"."script".">\n";
return $html;
}
?>
I need to keep this information in a php page because I am talking to a MSSQL database. Keeping this in mind, I need to be able to click (or double click preferably) on a row in the grid, and put the data in that row into corresponding input fields. I have been able to do it without the grid being dynamically loaded in php, but I need to be able to do it inside php. Any help would greatly be appreciated.
Beth
November 17,