<html>
<head>
<!-- include AW stylesheet and script -->
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="../../runtime/lib/aw.js"></script>
</head>
<body>
<script>
// insert javascript arrays produced by PHP functions
var myHeaders = ["id","workorderid","description","cost","chargetype","duration"];
var myCells = [
["55","40","time","125","hourly","2"],
["56","30","helpme","20","hourly","2"],
["57","50","small order","125","hourly","2"]
];
// create grid control
var obj = new AW.UI.Grid;
// set grid text
obj.setHeaderText(myHeaders);
obj.setCellText(myCells);
// set number of columns/rows
obj.setColumnCount(myHeaders.length);
obj.setRowCount(myCells.length);
// write grid to the page
document.write(obj);
</script>
</body>
</html>
<?php
require_once("MDB2.php");
$dsn = 'mysql://user:password@localhost/table';
$db =& MDB2::Connect( $dsn, array() );
if (PEAR::isError($db)) { die($db->getMessage()); }
$qry = "SELECT * FROM workorders";
$dataset = $db->query($qry);
// print MySQL query results as 2D javascript array
function aw_cells($dataset){
while ($record = $dataset->fetchRow(MDB2_FETCHMODE_BOTH)) {
foreach ($record as $value) {
echo $value;
}
}
}
This topic is archived.