3.0 beta 2

Get the values of selected row where the data came from Database Query

I have this code saved as basic3.php

<html>
<head>
    <title>Page</title>
    <style>
        *		
                {
                    -moz-box-sizing: border-box;
                }
            html	{ 
                    margin-bottom: 50px; 
                    padding: 0px; 
                    overflow: hidden
                }
            body	
                {
                    margin: 0px;
                    margin-bottom: 300px; 
                    padding: 0px; 
                    overflow: hidden; 
                    font: menu
                }
        .active-controls-grid
            {
            	border: 2px inset #ccc;
            }
        .active-grid-column 
            {
            border-right: 1px solid threedlightshadow;
            }
        .active-grid-row 
            {
            border-bottom: 1px solid threedlightshadow;
            } 
    </style>

    <!-- ActiveWidgets stylesheet and scripts -->
    <link href="../../runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
    <script src="../../runtime/lib/grid.js"></script>

    <!-- ActiveWidgets PHP functions -->
    <?php include("activewidgets.php") ?>

</head>
<body>

<?php

    // grid object name
    $name = "obj";

    // SQL query
    $query = "select * from Table";

    // database connection
    $connection = mysql_connect("localhost", "root", "pass");
    mysql_select_db("DB");

    // query results
    $data = mysql_query($query, $connection);

    // add grid to the page
    echo activewidgets_grid($name, $data);

?>
</body>
</html>


and this is the code of the include file activewidgets.php
<?php
function activewidgets_grid($name, &$data){

    $row_count = @mysql_num_rows($data);
    $column_count = @mysql_num_fields($data);


    $columns = "var ".$name."_columns = [\n";
    for ($i=0; $i < $column_count; $i++) {
        $columns .= "\"".@mysql_field_name($data, $i)."\", ";
    }
    $columns .= "\n];\n";

    $rows = "var ".$name."_data = [\n";
    while ($result = @mysql_fetch_array($data)) {
        $rows .= "[";
        for ($i=0; $i < $column_count; $i++) {
            $rows .= "\"".activewidgets_html($result[$i])."\", ";
        }
        $rows .= "],\n";
    }
    $rows .= "];\n";

    $html = "<"."script".">\n";
    $html .= $columns;
    $html .= $rows;
    $html .= "try {\n";
    $html .= "  var $name = new Active.Controls.Grid;\n";
    $html .= "  $name.setRowCount($row_count);\n";
    $html .= "  $name.setColumnCount($column_count);\n";
    $html .= "  $name.setDataText(function(i, j){return ".$name."_data[i][j]});\n";
    $html .= "  $name.setColumnText(function(i){return ".$name."_columns[i]});\n";
    $html .= "  document.write($name);\n";
    $html .= "}\n";
    $html .= "catch (error){\n";
    $html .= "  document.write(error.description);\n";
    $html .= "}\n";
    $html .= "</"."script".">\n";

    return $html;
}

function activewidgets_html($msg){

    $msg = addslashes($msg);
    $msg = str_replace("\n", "\\n", $msg);
    $msg = str_replace("\r", "\\r", $msg);
    $msg = htmlspecialchars($msg);

    return $msg;
}
?>


I need to accomplish the following:
1. Get the values of the cells of the selected row
2. Place those values in their corresponding text boxes for editing

So that when i click "Apply" button changes will be stored in the database and i'll just load the grid again to have an updated grid. I've read some posts here regarding selections but their data came from an array like in the examples/grid/basic.php where the array is under <script></script> tags. The problem is that the database queries are in <?php ?> tags and the examples regarding selections are all in <script>></script> tags. Can anyone help me in this ordeal?
Jel
October 18,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.