<!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD  HTML  4.0  Transitional//EN"  "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>DBMS example 5</title>
<link href="/styles/cs1.css" rel="stylesheet">

</head>
<body>
<h1>Dynamic Search Query</h1>

<p>This example generates a dynamic search query form for the VENDOR table. It allows querying on any combination of VEN_STATE and VEN_CODE. 
See the <a href="http:dbdemo5.phps">source</a> as well as the <A href="dbdemo5a.phps">source</a> for the
script that processes it.

<?php
    
    $user
="";
    
$upasswd="";
    
$dsn "DBMS";  // $dsn is the name of the db2 database    

    
$query "select distinct (VEN_STATE) from CIS3311.VENDOR" ;
    print 
"<p>query is: <code>$query</code><br>";
    
//connect 
   
    
$conn = @odbc_pconnect($dsn$user,$upasswd ); 
    if (!
$conn) {
        print 
"<strong>Connection error</strong>\n</html>";
        exit;
    }
       

     if (
$result odbc_Exec($conn$query)) {
        print 
"Query returned : " odbc_num_rows($result) . " rows";
    }

?>

<form ACTION="dbdemo5a.phtml" METHOD = GET>
<table border="1" bgcolor="silver" align="center">
<tr><th>VEN_CODE</th>
    <td><input type="text" name="VEN_CODE" SIZE="10" MAXLENGTH="10"></td>
</tr>
<tr><th>VEN_STATE</th>
<td><select NAME=VEN_STATE>
     <option selected value="ANY">Any
<?php
     
// now we retrieve the results as options
     
while (odbc_fetch_row($result)) {
         
$state odbc_result($result,"VEN_STATE");
         print 
'<option value="' $state "\">$state\n";
     }
?>
     </select>
</table>

<input type="submit" value="Search">
</form>

<P ALIGN=center>
<A HREF="dbdemo4.phtml">&lt;&lt; dbdemo4</A> | <A HREF="demos.phtml"> demos</A> | <A HREF="dbdemo5a.phtml">dbdemo5a</A>
</p>
</body></html>