Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-12-2009, 02:03 PM   PM User | #1
UD2006
Regular Coder

 
Join Date: Jul 2007
Location: Velsen Noord, Netherlands
Posts: 206
Thanks: 6
Thanked 0 Times in 0 Posts
UD2006 is an unknown quantity at this point
Depending dropdownmenus with mysql database

I have a problem and searched a lot on internet but haven't found the right solution for it. I found ajax but the one I found was hard coded and not from the database.

Here is my problem:

I have 2 dropdownmenu's, the second depending on the selection of the first. After the select of the second is also made an id from the database (linked to the second) is shown in a text field.

The code I already have can show the first dropdown filled but to refresh and fill the second I dont have yet (probably javascript, but dont know how).

Here is the code I have:
PHP Code:
<?php  
// open connection to MySQL server 
        
$connection mysql_connect('localhost''hgdhhgd''password'
        or die (
'Unable to connect!'); 
                                         
        
//select database 
        
mysql_select_db('bestellingen') or die ('Unable to select database!'); 
                                         
  
$sql 'SELECT * FROM hesk_programma ORDER BY Programma ASC'
  
$result mysql_Query($sql) or die ('Error in query: $query. ' mysql_error()); 

  
$menuContent2 ''$menuArray2 ''
  while ( 
$row mysql_fetch_array$result ) ) { 
    
$menuArray2    .= "      dArray['$row[Programma]'];\n"
    
$menuContent2 .= "        <option value=\"$row[Programma_id]\">$row[Programma]</option>\n"
  } 
    
   if( isset(
$_POST['Programma_id']) ){ 
    
  
$query 'SELECT * FROM hesk_projecten WHERE `Project_id` = \''.mysql_real_escape_string($_POST['Programma_id']).'\''
  
$result mysql_Query($sql) or die ('Error in query: $query. ' mysql_error()); 

  
$menuContent1 ''$menuArray1 ''
  while ( 
$row mysql_fetch_array$result ) ) { 
    
$menuArray1    .= "      dArray['$row[Project]'];\n"
    
$menuContent1 .= "        <option value=\"$row[Project_id]\">$row[Project]</option>\n"
  } 
}  
?> 
       
<select id="nameid2" name="name2">         
        <option name="select name2" value="select name2">Selecteer leverancier</option>         
        <?PHP echo $menuContent2?>       
</select> 

<select id="nameid1" name="name1">         
        <option name="select name1" value="select name1">Selecteer leverancier</option>         
        <?PHP echo $menuContent1?>       
</select> 

<name="projectnum" id="projectnum" size="20" value="<?php echo stripslashes(hesk_input($_SESSION['c_projectnum']));?>">
Any help would be great.
UD2006 is offline   Reply With Quote
Old 05-12-2009, 03:58 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Are you open to using jQuery? There is a very elegant plugin that handles this all for you, if you want to give it a shot.

http://www.codeassembly.com/Simple-c...in-for-jQuery/
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:05 PM.


Advertisement
Log in to turn off these ads.