Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to make dynamic drop boxes

    Hi,

    This is sort of a follow up to my last post

    I was wondering the best/easiest way to make dynamic drop boxes. Do I need to use Javascript?

    Here is some of the code I'm working with. I want select a meal type (breakfast, lunch, dinner, etc.) and then have the subsequent drop box pull up only the relevant meals

    Code:
    $sql_mealtype="SELECT typeID, typeName FROM mealtypes ORDER BY typeID";
    $result_mealtype=mysql_query($sql_mealtype);
    
    $mealtype_options="";
    while ($row=mysql_fetch_array($result_mealtype)) 
    	{
        $typeid=$row["typeID"];
        $typename=$row["typeName"];
        $type_options.="<OPTION VALUE=\"$typeid\">".$typename;
    	}
    Code:
    	<form>
    		Meal Type:
    		<br>
    		<select name="remove_type">
    		<option><?php echo $type_options?></option>
    
    	</form>
    
            <form>
    		Recipe:
    		<br>
    		<select>
    		<option>#####</option>
    		</select>
    	</form>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    The only way to do this directly with php, would be to ask for what 'meal' first, then submit the form, handle you're data and write a new select with just the items relating to it.
    This is actually how I'd do it anyway, then link AJAX to it to handle it behind the scenes and rewrite the new data. Even though forms that go through box after box just to get the specific related data is horrid looking, at least it will still function without the javascript involved.

    So, with the code you have above here, you would use the $typeid provided by you're selection menu to determine what meal type was selected, and query you're 'meals' (maybe?) table where the mealtype is $typeid to populate the next dropdown. That make sense?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •