Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop Down Menu: Option equal to all others in the list 1

Status
Not open for further replies.

phpkata

Programmer
Aug 5, 2004
6
US
I would like to create a drop down menu in a form that selects distinct arrays from a columname, inserts them into a drop down menu, but then I also want one of the options to be equal to all of the rest. I would end up with a drop down structured like this:

All colors
Red
Blue
Green
Purple

Any help would be greatly appreciated.

Thanks,
phpkata.
 
So set the default in the code itself

Assuming you are using php

Code:
$sql = "select distinct colors from tablename";

$result = mysql_query($sql);

if ($result){
  
   echo "<select name='color_list'>
         <option value=''>All Colors";

   while ($rows = mysql_fetch_array($result)){

      echo "<option value='".$rows[0].">".$rows[0];

   }//end while
  
   echo "</select>";

}//end if


Bastien

Cat, the other other white meat
 
Thanks for the reply Bastien. Maybe I was not clear though. I am creating a dynamic page with a search query with two options. Lets say the first is by Product. The second is by the Color. I need it so that if the user selects a Product and then chooses not to select the Color, it searches by Product and all of the Colors by default. The way my script is right now if the Color field is set to "All Colors" it returns no result.

Your help is very much appreciated. I am new to php and mysql and have been trying to fix this for two days now.

Here is what I have:

$query = "SELECT DISTINCT productName FROM eny_product_identifier ORDER BY productName";
$result = mysql_query($query)
or die ("Couldn't execute query.");

$query2 = "SELECT DISTINCT productGenColor FROM eny_product_colors ORDER BY productGenColor";
$result2 = mysql_query($query2)
or die ("Couldn't execute query2.");

echo "<form action='ShowProducts.php' method='POST'>\n";

echo "<select name='interest'>\n";
while ($row = mysql_fetch_array($result))
(
extract($row);
echo "<option value='$productName'>$productName\n";
}
echo "</select>\n";
echo "<br>";

if ($result2)
{
echo "<select name = 'interest2'>\n
<option value=''>All colors\n";
while ($row2 = mysql_fetch_array($result2))
{
echo "<option value='".$row2[0]."'>".$row2[0];
}
echo "</select>\n";
}
echo "<p><input type='submit' value='Select a Product Name and Color'>

</form>\n";

Thanks again,
phpkata.
 
The input form looks ok. It sounds like you need to test for color='' in ShowProducts.php. You've got product_id and product_color tables, may I assume that there's a "product" table with both? Like
prod_id | color | description| onhand | price | ....

I see it as:
$query = "select * from products where prod_id = '" . $_POST['interest'] . "'";
if ($_POST['interest2'] != '')
$query .= " and color = '" . $_POST['interest2'] . "'";
 
You Rock Igarner!!!!!!!!!!

THANKS A BUNCH!
phpkata.
 
and Bastien is chopped liver?

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
I'm Sorry :eek:(
EVERYONE HERE ROCKS!!!!!

Bastien, Igarner, and you too cLFlaVA!!!

THANKS MUCH!
phpkata.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top