I know you can hand-code a database query that prints out an HTML
table, but I'm looking for a re-suable control that can consume a DB
query and return HTML-compliant tabled data.
I'm aiming for something in the open source realm, if possible. Any
suggestions are appreciated.
phplens is probably the most complete/usable solution I've come across
C.
$connection = @mysql_connect('localhost', 'user', 'password');
@mysql_select_db('database', $connection);
$query = 'SELECT * FROM myTable LIMIT 0,10';
$dataset = @mysql_query($query, $connection);
// print MySQL query results as 2D javascript array
function aw_cells($dataset){
$rows = array();
while ($record = @mysql_fetch_row($dataset)) {
$cols = array();
foreach ($record as $value) {
$cols[] = '"'.addslashes($value).'"';
}
$rows[] = "\t[".implode(",", $cols)."]";
}
echo "[\n".implode(",\n",$rows)."\n];\n";
}
// print MySQL field names as javascript array
function aw_headers($dataset){
while ($field = @mysql_fetch_field($dataset)) {
$cols[] = '"'.$field->name.'"';
}
echo "[".implode(",",$cols)."];\n";
}
?>
<html>
<head>
<!-- include AW stylesheet and script -->
<link href="../../runtime/styles/system/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 = <?= aw_headers($dataset) ?>
var myCells = <?= aw_cells($dataset) ?>
// 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>
i will post the aw.js
I can't put the aw.js here but you can go http://www.activewidgets.com/
to see the datagrid script examples in there.
Not sure if it will suit you, but TYPO3 currently supports MySQL,
Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, DB2,
Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland
variants), Foxpro, Access, ADO, SAP DB, SQLite and ODBC.
What - no DBASE III support? :-)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================