3.2.0

ActiveWidgets 4 ADODB

activewidgets_grid for ADODB users

/*
include this file into your PHP page usage example:
*/

/*
// grid object name
$name = "obj";

// SQL query
$query = "select * from `table` limit 0,20";

// query results
$data = $connection->Execute($query) or die($connection->connection());

// add grid to the page
echo activewidgets_grid_adodb($name, $data, $connection);
*/

function activewidgets_grid_adodb($name, &$data, $connection)
{
$row_count = $data->RecordCount();
$column_count = $data->FieldCount();

$columns = "var ".$name."_columns = [\n";
for ($i=0; $i < $column_count; $i++)
{
$field_info = $data->FetchField($i);
$columns .= "\"".$field_info->name."\", ";
}
$columns = substr($columns,0,strlen($columns)-2)."\n];\n";

$rows = "var ".$name."_data = [\n";
while (!$data->EOF)
{
$rows .= "[";
for ($i=0; $i<$column_count; $i++) $rows .= "\"".activewidgets_html($data->Fields($i))."\", ";
$rows .= "],\n";
$data->MoveNext();
}
$rows = substr($rows,0,strlen($rows)-2)."\n];\n";

$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 .= " document.write($name);\n";
$html .= "}\n";
$html .= "catch (error){\n";
$html .= " document.write(error.description);\n";
$html .= "}\n";
$html .= "</"."script".">\n";

return $html;
}

ing.emmebì

ing.emmebì
September 26,

This topic is archived.

See also:


Back to support forum