SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help wanted: sub select for listbox

    Hi, i am having a slight problem, i need to select a value from a listbox, called cat_listbox.... This part works fine...

    Code:
    <select name="cat_listbox">; 
    		<?php 
    		$host = "";
    		$userName = "";
    		$password = "";
    		$database = "";
    		mysql_connect($host,$userName,$password) OR DIE("Unable to connect to database"); 
    		@mysql_select_db($database) or die( "Unable to select database");		
    		
    		$sql = "SELECT distinct Category_Name from Category ORDER BY Category_Name asc";
    		$result = mysql_query($sql);
    		while($menu = mysql_fetch_array($result))
    		 { 
    		 $menu1= $menu['Category_Name'];
      
    		 echo '<option value="'.$menu1.'">'.$menu1.'</option>';
    			}
    		
    		?>
    		
    	
    	  </select>
    But i need to select another value from the category selected above, and i cannot seem to get the value from the cat_listbox ...Anyone know how to solve this problem? The code for the second part is similar...

    Code:
    <select name="subcat_listbox">; 
    		<?php 
    	
    		$host = "";
    		$userName = "";
    		$password = "";
    		$database = "";
    		$temp = $cat_listbox;
    		mysql_connect($host,$userName,$password) OR DIE("Unable to connect to database"); 
    		@mysql_select_db($database) or die( "Unable to select database");		
    		echo $temp;
    		$cat="Select distinct Category_ID from Category where Category_Name = ".$temp." ";
    		$sql = "SELECT distinct Sub_Cat_Name from sub_category  where Category_ID IN $cat  ORDER BY Sub_Cat_Name asc";
    		$result = mysql_query($sql);
    		while($menu2 = mysql_fetch_array($result))
    		 { 
    		 $menu3= $menu2['Man_Name'];
      
    		 echo '<option value="'.$menu3.'">'.$menu3.'</option>';
    			}
    		?>
    Any help will be greatly appreciated...thanks

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I take it these are displayed in a form? and that the form elements are all named....
    is the second menu content dependant on the first menu's selcted option?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    I take it these are displayed in a form? and that the form elements are all named....
    is the second menu content dependant on the first menu's selcted option?
    Its all placed in a form, which will be submitted into a Database... T he Second menu contents is dependent on the First menus selected option...the second query works fine( i think) but when i select something in the first listbox, nothing happens in the second one....its always blank!!

    Any help would be appreciated

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    The page would have to be reloaded for the second menu's options to be processed and so displayed. The best way to do the menu select is via javascript. Have a look in the javascript forum for more answers.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    The page would have to be reloaded for the second menu's options to be processed and so displayed. The best way to do the menu select is via javascript. Have a look in the javascript forum for more answers.
    Can i post it to another page, and then use the first listbox value and do the second one....is that possible without writing it to the database??

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Yes, you can post the variable from the first select....
    just remember to name your form element so that you know what you are posting.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.....

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    although if you are going to post to another page, you might as well have it posting to the same page and keeping it more compact.
    eg:
    <first select menu>
    [submit] >> reloads page to give
    ...........<second select menu>
    ...........[submit]

    hope this makes sense
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This can be done without a page refresh by loading all data into arrays onload or by using JSRS. Google jsrs and it will show you the tut.

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    although if you are going to post to another page, you might as well have it posting to the same page and keeping it more compact.
    eg:
    <first select menu>
    [submit] >> reloads page to give
    ...........<second select menu>
    ...........[submit]

    hope this makes sense

    Yeah...it does...but how do u submit a page to itself...and then load the second menu??


Bookmarks

Posting Permissions

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