Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 31st, 2005, 06:00 PM
Authorized User
Join Date: Aug 2004
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Drop down issue(s)

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 "<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: ";
    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 ---
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down Issue SKhna ASP.NET 2.0 Basics 1 March 19th, 2008 06:29 AM
Drop Down List Control Issue PrinceAli0 ASP.NET 2.0 Basics 0 June 9th, 2006 01:46 PM
postback issue with drop downlists emachines ADO.NET 3 March 26th, 2005 01:36 PM
postback issue with drop downlists emachines General .NET 1 January 9th, 2005 09:42 PM

All times are GMT -4. The time now is 06:19 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.