while( $row= mysql_fetch_row(mysql_result) )
{
printf($row[0]); <-- this is the first variable
printf($row[1]); <-- second one
}
// grid object name
$name = "obj";
// SQL query
$query = "select * from `table` limit 0,20";
// database connection
$connection = mysql_connect("localhost", "user", "password");
mysql_select_db("database");
// query results
$data = mysql_query($query, $connection);
// add grid to the page
echo activewidgets_grid($name, $data);
function AW_array($name, $array, $header) {
// This function uses the ActiveWidget javascript code to print an Excel-like sortable list.
// Pass params:
//
// $name -> some name
// $header -> array containing header names for columns
// $data -> array: each element chould contain 1 row array (row count must match header count)
?>
<link href="grid.css" rel="stylesheet" type="text/css" ></link>
<script src="grid.js"></script>
<?
$row_count = sizeof($array);
$column_count = sizeof($header);
$columns = "var ".$name."_columns = [\n";
foreach ($header AS $column) {
$columns .= "\"".$column."\", ";
}
$columns .= "\n];\n";
$rows = "var ".$name."_data = [\n";
foreach ($array AS $row) {
$rows .= "[";
foreach ($row AS $element) {
if ($element <> $lastEl) {
$rows .= "\"".AW_html($element)."\", ";
$lastEl = $element;
}
}
$rows .= "],\n";
}
$rows .= "];\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);
}
This topic is archived.