Current location: Hot Scripts Forums » Programming Languages » PHP » Drop down trouble


Drop down trouble

Reply
  #1 (permalink)  
Old 07-15-05, 02:29 AM
phplearner phplearner is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Drop down trouble

the below codes first create a drop down with options dynamically taken from the database. by default it choses the first aircraft type from the database. for example the first aircraft type is A. So there will be a drop down with A selected by default.

when u click on the drop down and choose other aircraft type, the second drop down will appear after the form reloads. the second drop down is also populated by aircraft tail numbers from the database.

the 1st problem is, i want to change it in a way that when the page first loads, both drop downs is there already rather than the first drop down being there and the second appears after the first drop down is selected.

the 2nd problem is, after the page first loads, when the default aircraft type A is auto selected, no aircraft tail number is selected. i have to click on other aircraft type and then back to A again for the aircraft tail number of A to be selected in the second drop down. wat i really 1 is the default is A and the default for the 2nd drop down is the aircraft tail number of A when the page first loads.

i know its quite alot to ask but i really tried. mayb i dun really understand codes well enuf to make any changes. can some1 help mi?

<?
// get the aircraft type
$queryAircraftType = "SELECT DISTINCT AircraftType FROM aircraftinfo order by AircraftType";
$resultAircraftType = mysql_query($queryAircraftType)
or die ("couldn't execute query.");


// now you can display the results returned. But first we will display the search form on the top of the page
?>
<form method="get" name="search">
<select name="AircraftType" id="AircraftType" onchange="form.submit();">
<?php while($rowAircraftType = mysql_fetch_array($resultAircraftType)) {
if($rowAircraftType['AircraftType']==$_GET['AircraftType'])
{
echo "<option selected value='$rowAircraftType[AircraftType]'>$rowAircraftType[AircraftType]</option>"."<BR>";}
else
{
echo "<option value='$rowAircraftType[AircraftType]'>$rowAircraftType[AircraftType]</option>";}
}
?>
</select>
/
<?php
if (isset($_GET['AircraftType']))
{

$queryAircraftTailNo = "SELECT AircraftTailNo FROM aircraftinfo where aircrafttype='".$_GET['AircraftType']."'";
//echo $query;
$resultAircraftTailNo = mysql_query($queryAircraftTailNo)
or die ("couldn't execute query ".mysql_error());
if ($resultAircraftTailNo)
{
echo "<select name=\"AircraftTailNo\">";
while ($rowAircraftTailNo = mysql_fetch_array($resultAircraftTailNo))
{
if($rowAircraftTailNo['AircraftTailNo']==$_GET['AircraftTailNo'])
{
echo "<option selected value='$rowAircraftTailNo[AircraftTailNo]'>$rowAircraftTailNo[AircraftTailNo]</option>"."<BR>";}
else
{
echo "<option value='$rowAircraftTailNo[AircraftTailNo]'>$rowAircraftTailNo[AircraftTailNo]</option>";}
}// end of while
}// end of if
}
Reply With Quote
  #2 (permalink)  
Old 07-15-05, 12:39 PM
pamthieu pamthieu is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Get the cond of second query from the first query instead of Drop Down..

Try this out!

<form method="get" name="search">
<select name="AircraftType" id="AircraftType" onchange="form.submit();">
<?php
$resultAircraftType = mysql_query('SELECT DISTINCT AircraftType FROM aircraftinfo order by AircraftType')
or die('the Query is failed: ' . mysql_error());
//Build the Drop Down for the first record ...
$rowAircraftType = mysql_fetch_array($resultAircraftType);
$first_row=$rowAircraftType['AircraftType']; // Keep the first row just in case of first loading..
if($rowAircraftType['AircraftType']==$_GET['AircraftType'])
{
echo "<option selected value='$rowAircraftType[AircraftType]'>$rowAircraftType[AircraftType]</option>"."<BR>";}
else
{
echo "<option value='$rowAircraftType[AircraftType]'>$rowAircraftType[AircraftType]</option>";
}
//--end of first record..

while($rowAircraftType = mysql_fetch_array($resultAircraftType)) {
if($rowAircraftType['AircraftType']==$_GET['AircraftType'])
{
$first_row=$rowAircraftType['AircraftType'];//change the value if GET exists
echo "<option selected value='$rowAircraftType[AircraftType]'>$rowAircraftType[AircraftType]</option>"."<BR>";}
else
{
echo "<option value='$rowAircraftType[AircraftType]'>$rowAircraftType[AircraftType]</option>";}
}
?>
</select>

<?php
//if (isset($_GET['AircraftType']))
//{

$queryAircraftTailNo = "SELECT AircraftTailNo FROM aircraftinfo where aircrafttype='".$first_row."'"; //Get the cond from the query instead of Drop Down..
//echo $query;
$resultAircraftTailNo =mysql_query($queryAircraftTailNo)
or die ("couldn't execute query ".mysql_error());
if ($resultAircraftTailNo)
{
echo "<select name=\"AircraftTailNo\">";
while ($rowAircraftTailNo = mysql_fetch_array($resultAircraftTailNo))
{
if($rowAircraftTailNo['AircraftTailNo']==$_GET['AircraftTailNo'])
{
echo "<option selected value='$rowAircraftTailNo[AircraftTailNo]'>$rowAircraftTailNo[AircraftTailNo]</option>"."<BR>";}
else
{
echo "<option value='$rowAircraftTailNo[AircraftTailNo]'>$rowAircraftTailNo[AircraftTailNo]</option>";}
}// end of while
//}// end of if}
?>

it can be tested here: http://gms.locatehomes.com/aircraft.php will be removed in 2 days..
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto populate drop down list? awiekupo PHP 6 10-31-09 11:47 AM
trouble with the display of results and drop down list.. SummerL PHP 0 07-11-05 10:38 AM
Drop Down menu order peterc PHP 1 08-20-04 02:23 AM
drop down menu problem !!! nurqeen PHP 1 02-08-04 08:07 PM
drop the lowest number TheLaughingBandit ASP 2 08-30-03 01:57 PM


All times are GMT -5. The time now is 06:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.