<!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 processes the query from <a href="dbdemo5.phtml">dbdemo5</a>
It allows querying on any combination of VEN_STATE and VEN_CODE. 
See the <a href="http:dbdemo5a.phps">source</a></p>

<?php
require_once('register_variables.pinc');
// build the where clause

variable_register('GET','VEN_CODE','VEN_STATE');
if (  
$VEN_CODE ) {
    
$WHERE "VEN_CODE ='" $VEN_CODE "'";
} else {
    
$WHERE  "" ;
}
if (
$VEN_STATE != "ANY") {
   
$STATE "VEN_STATE = '" $VEN_STATE "'";
   if (
$WHERE)  $WHERE  $WHERE " AND $STATE";
   else 
$WHERE $STATE;

}
if (
$WHERE$WHERE "WHERE $WHERE";

$COLUMNS 'VEN_CODE AS "VENDOR CODE", VEN_PH AS "VENDOR PHONE", VEN_CONTACT_NAME AS "CONTACT_PERSON", VEN_STATE AS "STATE"';

$query "SELECT $COLUMNS FROM CIS3311.VENDOR $WHERE";
print 
$query "\n<br>";
// print "Ven_code: $VEN_CODE <br>\n  Ven_state: $VEN_STATE";
    //connect 
    
$user="";
    
$upasswd="";
    
$dsn "DBMS";  // $dsn is the name of the db2 database    

    
$conn = @odbc_connect($dsn$user$upasswd ); 
    if (!
$conn) {
        print 
"Error in connection\n</html>";
        exit;
    }
       

     if (
$result odbc_Exec($conn$query)) {
        if (
odbc_num_rows($result) ) {
            
odbc_result_all($result"border = 1 align=\"center\""); 
    } else  {
        print 
"<strong>No Rows Found</strong>";
         }
    }

?>
<P ALIGN=center>
<A HREF="dbdemo5.phtml">dbdemo2</A> | <A HREF="demos.phtml">demos</A> </P>

</body></html>