U.S. Geological Survey

PHP code using MySQL database

<?
    $dbh = mysql_connect ($dbhost,$auth_user,$auth_pw);
    mysql_select_db ($dbname);

    $v = $_REQUEST['parent']; // from an HTML form

    if ($request_method == "GET") {
        $query = "select code,name from term where parent='$v'";
        $result = mysql_query ($query,$dbh);
        $n = mysql_num_rows ($result);
        for ($i=0; $i < $n; $i++) {
            $row = mysql_fetch_row ($result);
            $code = $row[0];
            $name = $row[1];
            echo "<li>";
            echo "<A HREF=\"term.php?term=$code\">"
            echo "$name</A>";
            echo "</li>\n";
            }
        }

    if ($request_method == "POST") {
        // ... service POST request
        }

    mysql_close ($dbh);
?>

Dynamic web applications
Peter Schweitzer, U.S. Geological Survey