:: Forum >> Version 2 >>

Data from SQL

When i try to load the data from sql i get the following result
name.'"'; } echo "[".implode(",",$cols)."];\n"; } ?>
 
when i use this code

<?php

$connection 
= @mysql_connect('localhost''root''******');
@
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/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 = <?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>
 
Langras
Sunday, April 20, 2008
Obviously, you have a bug in this line of code -
$cols[] = '"'.$field->name.'"'
 
Anthony
Monday, April 21, 2008



This topic is archived.

Back to support forum

Forum search