<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Select a client and see their data!</title>
<!--
This coding constructs an option select box
pre populated with client codes from an ODBC
database.
On selecting the correct client code the database
is queried and displays all related information.
-->
<style type="text/css">
<!--
body {font-family:verdana; font-size:11px; font-style:normal; font-weight:normal;}
th {color:white; background-color:gray; font-size:11px;}
td {background-color: silver; font-size:11px;}
-->
</style>
</head>
<body>
<?php
// odbc_query.php
$odbc_dsn = "timeandfees_db";
$odbc_userid = "";
$odbc_password = "";
if (!isset($_POST['submit'])) { // Step 1: fill initial form and present it
$tmp = array();
$tmp[] = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
$tmp[] = '<select name="custname" size=1>';
$query = "SELECT Clients.ClientKey FROM clients ORDER BY Clients.ClientKey";
if(!($odbc_db = odbc_connect($odbc_dsn, $odbc_userid, $odbc_password)))
die ("Could not connect ot ODBC data source $odbc_dsn");
if(!($odbc_rs = odbc_do($odbc_db, $query)))
die("Error executing query $query");
$num_cols = odbc_num_fields($odbc_rs);
if($num_cols < 1) die("Query returned an empty set");
while(odbc_fetch_row($odbc_rs)) $tmp[] = '<option>' . odbc_result($odbc_rs,'ClientKey') . '</option>';
$tmp[] = '</select>';
$tmp[] = '<input type="submit" name="submit" value="Display Time and Fees Information">';
$tmp[] = '</form>';
echo implode("\n",$tmp)."\n";
}
else { // Step 2: Display data
$tmp = array();
// $valid_cust = validate($_POST['custname']); //make sure that input is in the format you are expecting
$valid_cust = $_POST['custname'];
$query = "SELECT Clients.ClientKey, Clients.CoyName, Addresses.* FROM Addresses INNER JOIN Clients ON Addresses.AddrKey = Clients.AddrKey where Clients.ClientKey = '" . $valid_cust . "'";
if(!($odbc_db = odbc_connect($odbc_dsn, $odbc_userid, $odbc_password)))
die ("Could not connect ot ODBC data source $odbc_dsn");
if(!($odbc_rs = odbc_do($odbc_db, $query)))
die("Error executing query $query");
$num_cols = odbc_num_fields($odbc_rs);
if($num_cols < 1) die("Query returned an empty set");
?>
<table summary="" style="{width:100%;}">
<tr>
<?php
for($a=1;$a<=$num_cols;$a++)
{
?>
<th style="{text-align:left;}">
<b>
<?php
echo odbc_field_name($odbc_rs, $a);
?>
</b>
</th>
<?php
}
?>
</tr>
<?php
while(odbc_fetch_row($odbc_rs))
{
?>
<tr>
<?php
for($a=1;$a<=$num_cols;$a++)
{
$data = odbc_result($odbc_rs, $a);
echo "<td>$data</td>";
}
?>
</tr>
<?php
}
}
?>
</table>
</body>
</html>