:: Documentation >>

PHP/MySQL

Simple PHP/MySQL example. Defines two PHP functions - aw_cells() and aw_headers() which generate the arrays in javascript code format.

<?php

$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/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>

Comments

HI There eshaa (1)
PHP/MySQL ReFetch Data In Grid Andy (1)
javascript php call fails Andy (3)
How do I read the grid array data and build the SQL UPDATE $str Andy (0)
Como cambio el color de fondo de una fila con datos Paco Aguiar (2)
PHP with ODBC connection to MS ACCESS (0)
Getting AW is Undefined Ray (1)
inghenieriamarazul at yahoo.es (1)
Load data dynamically using JSP as server side script... Shan Justus. (2)
PHP MySQL Example Errors Jeremy Savoy (5)
Simple PHP/MySQL example Alex (ActiveWidgets) (22)
phpsql code Eric Ilavia (4)
Export excel to Mysql database E (1)
How change the table size? paula enews@iespana.es (2)
get an error if without trim() winotosw (0)

Documentation:

Recent changes:

2.6.4
2.6.3
2.6.2
2.6.1
2.6.1
2.6.0
2.5.0 - 2.5.6
2.5.6
2.5.0 - 2.5.5
2.5.5