CodeThatGrid - Grid Generation from the Database Example

CodeThatGrid - Grid Generation from the Database Example

<php
function create_definition()
{
	global $db;
	$definition = "";
	$result = mysql_query("select * from test_data");
	$data = "[";
	$num_result = mysql_num_fields ($result);
	for ($i = 0; $i<$num_result; $i++)
	{
		if ($i>0) $data .= ', ';
		$data .= '["' . @mysql_result($result, $i, "id") . '", ' .
		'"' . @mysql_result($result, $i, "username") . '", ' .
		'"' . @mysql_result($result, $i, "email") . '"]';
	}
	$data .= ']';
	$result2 = db_query("select * from test_structure");
	$coldef = "[";
	$num_result2 = db_numrows($result2);
	for ($i = 0; $i<$num_result2; $i++)
	{
		if ($i>0) $coldef .= ', ';
		$coldef .= '{title: "' . db_result($result2, $i, "title") .
		'", titleClass: "", type: "' . db_result($result2, $i, "col_type") .
		'", width: ' . db_result($result2, $i, "col_width") .
		', alignment: "' . db_result($result2, $i, "col_alignment") .
		'", compareFunction: compare, isVisible: true, '.
		' useAutoIndex: false, useAutoFilter: false } ';
	}
	$coldef .= ']';
	$definition = "var gridDef={ useExportBar :false, useMultiSort:true,
	useColTitle: true, data: $data, colDef: $coldef ";
	$definition .= ', rowStyle : {	markClass:  "mark",	darkClass:  "dark",	' .
	' lightClass: "light", hoverClass: "hover"},
	tablestyle : {tableClass:{borderwidth:"2",borderstyle:"solid",
	bordercolor:"#bbbbbb",backgroundcolor:"#ffffff"},
	thClass : {fontfamily:"Verdana", fontsize:"12px", color:"#000000",
	borderwidth:"1", borderstyle: "solid", bordercolor: "#cfcfcf",
	backgroundcolor:"#ececec"}, tdClass : {fontfamily:"Verdana",
	fontsize:"12px", color:"#000000"}, bgcolor : "#bbbbbb",
	x : 0, y : 0, width: 660, height: 480}};';
	return $definition;
}
?>
       
<html>
 <head>
  <title>Grid Test</title>
  <script language="javascript" src="/codethatsdk.js"></script>  
  <script language="javascript" src="codethattype.js"></script>         
  <script language="javascript" src="codethatgridpro.js"></script>   
  <link rel="stylesheet" href="style.css">  
  <link href="/common_codethat.css" rel="stylesheet" type="text/css">
  <script language="javascript1.2">
<!--
var DATE_FORMAT = "dd.mm.yyyy";
var EMPTY_ROW = "...";
var DEFAULT_COLDEF = {
	title : "",
	titleClass : "",
	type : "String", //the default type
	width : 0, //auto
	alignment : "", //auto
	compareFunction : compare,
	isVisible : true,
	useAutoIndex : true,
	useAutoFilter : false
};
<? echo create_definition(); ?>
//-->
</script> 
 </head>
 <body>
  
   <script language="javascript1.2">
<!--
var g = new CCodeThatGrid("g", 5, 6);
g.init(gridDef);
g.doAction(); 
//-->
</script>       

 </body>
</html>