!--www--CodeThatTable - Table Generation from the Database Example!--www/--!--all--code that works!!--all/--

CodeThatTable - Table Generation from the Database Example

<?php
     require('code_html.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 = mysql_query("select * from test_structure");
 
 $coldef = "[";

 $num_result2 = mysql_num_fields($result2);

 for($i=0; $i<$num_result2; $i++)
 {
   if($i>0) $coldef .= ', ';
   $coldef .= '{title: "' . @mysql_result($result2, $i, "title") . 
              '", titleClass: "", type: "' . @mysql_result($result2, $i, "col_type") . 
		      '", width: ' . @mysql_result($result2, $i, "col_width") . 
	          ', alignment: "' . @mysql_result($result2, $i, "col_alignment") . 
         	  '", compareFunction: compare, isVisible: true, '.
              ' useAutoIndex: false, useAutoFilter: false } ';
 }

 $coldef .= ']';

 $definition = "var gridDef={ amountPerPage:5, useMultiSort:false, data: $data, colDef: $coldef ";
 
 $definition .= ', keyCol : "ID", rowStyle : { 	markClass:  "mark",	darkClass:  "dark",	' .
                ' lightClass: "light", hoverClass: "hover"}};';

 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="codethattablepro.js"></script>   
  <link rel="stylesheet" href="style.css">  
  <script language="javascript1.2"> <? echo create_definition(); ?> </script> 
 </head>
 <body>
  
   <script language="javascript">               
   var CodeThatTable = new CCodeThatTable("CodeThatTable");            
   CodeThatTable.loadData(gridDef);      
   CodeThatTable.doAction();        
   </script>       
  
 </body>
</html>