help with double drop down menu populated from mysql please!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
alixir
Forum Newbie
Posts: 8
Joined: Wed Jun 15, 2005 3:27 am

help with double drop down menu populated from mysql please!

Post by alixir »

Hi there, took ages to understand how to get this far!!! Looking to see if anybody has any way of helping me with the following.

I have two tables:

clients (client_id, client_name)
location (client_id, client_site_name)

The drop down for the clients I have already written in the code below. I have the logical solution in my head already and all the conditions that need to be met for the second drop down to work.....

Trying to make this work in PHP is driving me nuts.....just doesn't seem to work the same way as programming in basic! (understandably!)

Any help with this would be great, I could then get on and create all the other drop downs for the sections......

Cheers!

code so far:

CONFIG.INC.PHP
<?php

// Variables for the connection
$dbserver="localhost";
$dbusername="root";
$dbpassword="password";
$dbtablename="clients";
$db="fixitsupport";

?>

***************************DBCONNECT.INC.PHP
<?

include_once ("config.inc.php"); ?>

<?php

// This will connect to the database or return an error

// String containing the mysql connection command
$dbconnect = @mysql_connect($dbserver, $dbusername, $dbpassword) or die (mysql_error());

// Command to connect to the database
mysql_select_db($db, $dbconnect) or die (mysql_error);

?>

**********************DROPDOWN.PHP
<?

// Include the Database connection script
include_once ('dbconnect.inc.php');

// Perform the mysql query on the clients table

$link = mysql_connect ($dbserver, $dbusername, $dbpassword);
$query = "Select client_name from $dbtablename order by client_name";
$results = mysql_db_query($db, $query, $link);

?>

Which Client would you like to select?
<select name = "clientdropdownselection" size="1">
<Option Value=" ">Select One:</option>
<? //Begins PHP
for($u=0;$u<mysql_num_rows($results); $u++) {
$client=mysql_result($results,$u,'client_name');
?>

<option value="<? echo($client); ?>"><? echo($client); ?></option>

<? //Begins PHP

}

?>

</select>

<form method=post action="pagetolinkto.php">
<input type=submit value="Next">
</form>
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Welcome to the forum. please use PHP tags when posting code.

Your question has been asked numerous times here. Check out the search.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

cross-posting is very uncool. Locked.

original thread:
viewtopic.php?t=37293
Locked