<!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD  HTML  4.0  Transitional//EN"  "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
  <TITLE>DBMS example 4</TITLE>
<link href="/styles/cs1.css" rel="stylesheet">
<?php
require ("table.pinc");
?>
</HEAD>
<BODY>
<h1>Simple Query, Fancy result</h1>
This script (see <a href="dbdemo4.phps">source</a>) 
 formats the vendor address and webpage as HREF's. 
It uses some functions from <a href="http://cs1.mcm.edu/fragments/table.phps">table.phps</a>.

<P>
<?php

//we don't need a username & password when tables are accessible to web
    
    
$user="";
    
$upasswd="";
    
$dsn "DBMS";  // $dsn is the name of the db2 database

    
$columns 'ven_code, ven_name, ven_contact_name, ven_email, ven_web_page'
    
$query "select $columns from CIS3311.VENDOR order by VEN_CODE";
    print 
"<p>query is: <code>$query</code><br>";
    
//connect 
   
    
$conn = @odbc_connect($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";

    print 
"<table border = 1 cellspacing = 2>\n";
    while (
odbc_fetch_row($result)) {

           
$row maketd(odbc_result($result"VEN_CODE") ) .
              
maketd(odbc_result($result"VEN_CONTACT_NAME") ) ;
           
$email odbc_result($result"VEN_EMAIL") ;
           if (
$email) {
           
$row $row 
          
maketdmakehref($email"mailto:" )  );
           } else {
           
$row $row maketd("&nbsp;") ;
       }
       
$webpage =  odbc_result($result"VEN_WEB_PAGE") ;
       if (
$webpage) {
           
$row $row 
          
maketdmakehref($webpage"http://"
                     
) );
       } else {
           
$row $row maketd("&nbsp;") ;
       }
           
$row makerow($row);
       print 
$row;
    }   
// end while

       
print "</table>\n";
     }
    
odbc_close($conn);
?>
<P ALIGN=center>
<A HREF="dbdemo3.phtml">dbdemo3</A> | <A HREF="demos.phtml">demos</A> | <A HREF="dbdemo5.phtml">dbdemo5</A></P>
</BODY></HTML>