:: Forum >>

PHP without MySQL

How can I show variables instead of MySQL-Results?
bot
Thursday, February 17, 2005
No one?
Thursday, February 17, 2005
Try:
while( $row= mysql_fetch_row(mysql_result) )
{
printf($row[0]); <-- this is the first variable
printf($row[1]); <-- second one
}
dbkdesign
Wednesday, February 23, 2005
You mean while( $row= mysql_fetch_row(mysql_result) )
{
printf($row[0]); <-- this is the first variable
printf($row[1]); <-- second one
}


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

    // SQL query
    $query = "select * from `table` limit 0,20";

    // database connection
    $connection = mysql_connect("localhost", "user", "password");
    mysql_select_db("database");

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

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

?
Saturday, March 5, 2005
A little quick and dirty example of a function which prints the AW list using an array as input instead of MySQL query output.
function AW_array($name, $array, $header) {
    // This function uses the ActiveWidget javascript code to print an Excel-like sortable list.
    // Pass params:
    //
    // $name -> some name
    // $header -> array containing header names for columns
    // $data -> array: each element chould contain 1 row array (row count must match header count)

    ?>
    <link href="grid.css" rel="stylesheet" type="text/css" ></link>
    <script src="grid.js"></script>
    <?

    $row_count = sizeof($array);
    $column_count = sizeof($header);

    $columns = "var ".$name."_columns = [\n";

    foreach ($header AS $column) {
        $columns .= "\"".$column."\", ";
    }
    $columns .= "\n];\n";

    $rows = "var ".$name."_data = [\n";
    foreach ($array AS $row) {
        $rows .= "[";
        foreach ($row AS $element) {
            if ($element <> $lastEl) {
                $rows .= "\"".AW_html($element)."\", ";
                $lastEl = $element;
            }
        }
        $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);
}
Me
Sunday, December 11, 2005

This topic is archived.


Back to support forum

Forum search