Drop down menu

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

Post Reply
Cavolks
Forum Newbie
Posts: 3
Joined: Thu Sep 20, 2007 8:08 am

Drop down menu

Post by Cavolks »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I got my drop down menu to populate from my database, now the problem I am having is...When the user selects from the drop down menu, I want that selection to be submitted so I can use it on another page.  Here is the code i have so far. All it is right now is my drop down being populated from my database.

Code: Select all

<form id="form1" name="form1" method="post" action="welcome.php">
  <label>Location
  <select name="select">
    <?php
do {  
?>
    <option value="<?php echo $row_list['name']?>"><?php echo $row_list['name']?></option>
    <?php
} while ($row_list = mysql_fetch_assoc($list));
  $rows = mysql_num_rows($list);
  if($rows > 0) {
      mysql_data_seek($list, 0);
	  $row_list = mysql_fetch_assoc($list);
  }
?>
  </select>
  </label>
</form>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

First of all i assume you have already setup a query!

Secondly, you need ; after your variable in the do loop - in btoh instances.

Finally, why dont you just use a while loop to populate the select menu in the first place?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

This was mistakenly posted as a new thread.
Cavolks wrote:My drop down menu works, my next problem is, how do i get a 2nd menu filled with different information from the equipment table and have the selections from both of the drop down menus submit with only one button?

Code: Select all

<?php
  include("misc.php");                                 

  $cxn = mysqli_connect($host,$user,$password,$database)   
         or die ("couldn't connect to server");
  $head = "SELECT * FROM equipment where wear = 'head'"; 
  $result = mysqli_query($cxn,$head) or die ("Couldn't execute query.");        

  /* Create form containing selection list */
  echo "<form action='display.php' method='POST'>\n";
  echo "<select name='eq'>\n";
  $counter=1;                                       
  while($row = mysqli_fetch_assoc($result))            
  {
     extract($row); 
	 echo "<option>$name</option>";                                    
     $counter++;                                       
  } 
?>
<input name='submit' type='submit' value='Submit'>
</select></form>
Cavolks
Forum Newbie
Posts: 3
Joined: Thu Sep 20, 2007 8:08 am

drop down

Post by Cavolks »

I now have two drop down menus and right now they are populating the same information. The information in my database is divided up by wear location(head or feet). I can't figure out how to split these up after I've made my query and put each into their own drop down box.

Code: Select all

<?php
include("misc.php");

$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn't connect to server");
$query = "SELECT * FROM equipment";  
$result = mysqli_query($cxn,$query) or die ("Couldn't execute query.");

/* Create form containing selection list */
$name_arr = array();
$equip_arr = array();

while($row = mysqli_fetch_assoc($result))
{
extract($row);
$name_arr[] = $name;
$equip_arr[] = $name;
}
echo "<form action='display.php' method='POST'>\n";
echo "<select name='head'>\n";
foreach ($name_arr as $name){
echo "<option>".$name."</option>";
}
echo "</select><BR>";
echo "<select name='feet'>\n";
foreach ($equip_arr as $name){
echo "<option>".$name."</option>";
}
echo "</select><BR>";

?>
<input name='submit' type='submit' value='Submit'>
</select></form>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What do you mean by "split them up?"
Cavolks
Forum Newbie
Posts: 3
Joined: Thu Sep 20, 2007 8:08 am

drop down

Post by Cavolks »

my database looks something like this...

wear name
head cap
head helmet
feet shoes
feet boots

I want one drop down to display cap and helm
and the other shoes and boots
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Okay, you need a conditional that looks at "wear." It will associate "head" with the head array, and "feet" with the feet array.
Post Reply