next up previous contents index
Next: Several Questions and Treatments Up: Examples Previous: Using SQL-Databases to pass   Contents   Index


Viewing SQL-Tables (PHP, MySQL)

When you work with SQL-tables the following script might be helpful. Is displays the contents of one table (specified in the variable table). Simply call the page with the extension ?table=tablename

<HTML>
<BODY>
<TABLE BORDER=1><TR>
<?
    require ("header.inc"); // this defines $user and $pass

        
    mysql_connect("localhost",$user,$pass);
    mysql_select_db ("expCrash");

    if ($DELETE)
        mysql_query ("DELETE FROM $table");

    $result = mysql_query ("SELECT * FROM $table");
    $fields = mysql_num_fields($result);
    for ($i=0;$i<$fields;++$i) {
        $name=mysql_field_name ($result,$i); 
        echo "<TH>$name</TH>";
    }
    echo "</TR>\n";
    while ($row=mysql_fetch_array($result)) {
        echo "<TR>";
        for ($i=0;$i<$fields;++$i) {
            $name=mysql_field_name ($result,$i); 
            echo "<TD>$row[$name]</TD>";
        }
        echo "</TR>\n";
    }
?>
</TABLE>
<?
    echo "<FORM METHOD=POST ACTION=$SCRIPT_NAME>
    <INPUT TYPE=HIDDEN NAME=table VALUE=$table>
    <INPUT TYPE=SUBMIT NAME=UPDATE VALUE=Update>
    <INPUT TYPE=SUBMIT NAME=DELETE VALUE=Clear>
    </FORM>";
?>
</BODY>
</HTML>


next up previous contents index
Next: Several Questions and Treatments Up: Examples Previous: Using SQL-Databases to pass   Contents   Index
Oliver Kirchkamp