:: Forum >> Version 1 >>

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-sizingborder-box;
                }
            
html    
                    
margin-bottom50px
                    
padding0px
                    
overflowhidden
                
}
            
body    
                
{
                    
margin0px;
                    
margin-bottom300px
                    
padding0px
                    
overflowhidden
                    
fontmenu
                
}
        .
active-controls-grid
            
{
                
border2px inset #ccc;
            }
        .
active-grid-column 
            
{
            
border-right1px solid threedlightshadow;
            }
        .
active-grid-row 
            
{
            
border-bottom1px 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
Tuesday, October 18, 2005



This topic is archived.

Back to support forum

Forum search