Hello all.
I'm designing a drop down search list drawing data from a MySQL database. It goes likes this:
First drop down list :
Client
Second drop down list : Depending on the 1st, the related
City is shown
Third drop down list : Depending on 1st and 2nd lists, the
Contact is shown
Firstly, everything is working properly (drawing from database). Logically, when I select the client, it then shows the city, which in turn, shows the contact. After the contact is selected, the rest of the information is shown.
However, when I implemented the code itself it does the following:
After selecting the city,
this line actually disappears and is replaced by the contact selection. In other words, it displays 2 lines instead of 3.
I've tried seperating the contact selection into its own table, but it still replaces the city selection display line regardless. I'm totally stumped.

Any suggestions?
This is the code itself. Don't mind the mess :D:
--- start of code fragment ---
if ($Cmd == 'CHANGE') {
ECHO "<TABLE BORDER='0' WIDTH='75%' ALIGN='center'>";
ECHO "<TR><TH>Enter the required search parameters</TH>";
// Check if there are any Clients to list
$query = "SELECT count(*) from Clients";
$result = mysql_query($query);
if(!$result) error_message(sql_error());
// If there are no Clients in the DB, user has logical option to go back
$query_data = mysql_fetch_row($result);
$record_count = $query_data[0];
$Redirect = $_GET['Redirect'];
if ((!$record_count) || ($_GET['Flag'] != 'ES')){
ECHO "<TH><A HREF='?Cmd=NEW&Flag=SS&Redirect=$Redirect'><IMG SRC='..\images\Nav\ReturnToPreviousScreen.jpg' ALT='Go back to the Add Client Screen'></A></TH>";
}
//else {
// ECHO "</TR></TABLE>";
//}
ECHO "<FORM NAME='GetClient' METHOD='post' ACTION = '?Cmd=CHANGE&Flag=CS&Redirect=$Redirect'>";
$query = "SELECT DISTINCT Client from Clients order by Client";
ECHO "<TR><TD COLSPAN='2' ALIGN='center'><BR>Client: ";
// Select the Client first
ECHO "<SELECT NAME='Client'>";
$query_data = mysql_query($query);
ECHO "<OPTION VALUE='*'>Please select the cientele</OPTION>";
while ($row = mysql_fetch_array($query_data)) {
$Client = $row['Client'];
// The posting value is from selecting the city, the get value is from selecting the contact
IF (ISSET($_POST['Client'])) {
$Temp_Client = $_POST['Client'];
}
IF (ISSET($_GET['Client'])){
$Temp_Client = $_GET['Client'];
}
// So long as a client is selected, show the current selection
IF (!EMPTY($Temp_Client)) {
$Temp_Client = stripslashes($Temp_Client);
ECHO "<OPTION VALUE=$Client";
IF ($Client == $Temp_Client) {
ECHO " SELECTED";
}
ECHO ">";
ECHO str_replace("_"," ",$row['Client']);
ECHO "</option>";
} ELSE { ECHO "<OPTION VALUE=$Client>" . $row['Client'] . "</option>";
}}
ECHO "</select>";
//ECHO "</TD><TD ALIGN='CENTER' VALIGN='MIDDLE'>";
ECHO "<INPUT TYPE='image' SRC='..\images\Action\SelectClient.jpg'>";
//ECHO "<INPUT TYPE='Submit' VALUE='Select Client'>";
ECHO "</FORM></TD>";
// Once the Client is selected, select the related city for this client
if ($_GET['Flag'] == 'CS') {
$Client = $_POST['Client'];
$Client = stripslashes($Client);
$Redirect = $_GET['Redirect'];
ECHO "<FORM NAME='GetClient' METHOD='post' ACTION = \"?Cmd=CHANGE&Client=$Client&Flag=CC&Redirect=$Red irect\">";
$query = "SELECT DISTINCT City from Clients where Client = \"$Client\" order by City";
//ECHO $query;
ECHO "<TR><TD COLSPAN='2' ALIGN='center'>City: ";
ECHO "<SELECT NAME='City'>";
if (($Client == '*') || ($Client == '')) {
ECHO "<OPTION>Choose a Client first</OPTION>";
} ELSE {
$query_data = mysql_query($query);
while ($row = mysql_fetch_array($query_data)) {
$City = $row['City'];
$City = str_replace(" ", "_", $City);
// echo $City;
ECHO "<OPTION VALUE=$City>" . $row['City'] . "</option>";
}
ECHO "</select>";
ECHO "<INPUT TYPE='image' ALIGN='middle' SRC='..\images\Action\SelectCity.jpg'>";
ECHO "</FORM></TD></TR>";
}
}
// Once the city is selected, select the contact person
if ($_GET['Flag'] == 'CC') {
$Client = $_GET['Client'];
$Client = stripslashes($Client);
$City = $_POST['City'];
$Redirect = $_GET['Redirect'];
ECHO "<FORM NAME='GetClient' METHOD='post' ACTION = \"?Cmd=CHANGE&Client=$Client&City=$City&Flag=ES&Re direct=$Redirect\">";
$query = "SELECT Contact from Clients where Client = \"$Client\" && City = \"$City\" order by Contact";
ECHO "<TR><TD COLSPAN='2' ALIGN='center'>Contact: ";
ECHO "<SELECT NAME='Contact'>";
if (($Client == '*') || ($Client == '')) {
ECHO "<OPTION>Choose Client</OPTION>";
} ELSE {
$query_data = mysql_query($query);
while ($row = mysql_fetch_array($query_data)) {
$Contact = $row['Contact'];
$Contact = str_replace(" ", "_", $Contact);
echo $City;
ECHO "<OPTION VALUE=$Contact>" . $row['Contact'] . "</option>";
}
ECHO "</select>";
ECHO "<INPUT TYPE='image' ALIGN='middle' SRC='..\images\Action\SelectContact.jpg'>";
ECHO "</FORM></TD></TR>";
}
}
--- end of code fragment ---