This is a discussion on newbie help please!!!!!!!!! within the alt.comp.lang.php forums, part of the PHP Programming Forums category; below is the code to populate a drop down menu with information from a database. i use the onChange to ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
below is the code to populate a drop down menu with information from a
database. i use the onChange to refresh the page so it can print the slected value to the screen "<SELECT NAME=\"subject_code\" valign=bottom onChange='document.forms[0].submit()'> however all that happens is that it refreshes, what i am ultimatly is trying to do is populate a second dropdown menu using the subject_code to draw the info out of the db thanks in advnace <? /************************************************** ************************* ********************** * read from the database, then wrote the resuts to the scree ************************************************** ************************** *********************/ //Conect to the database $db=mysql_connect("******","*******", "********") or die ("cant connect"); mysql_select_db("stealthcml",$db) or die ("cant change"); //Query the database $sql = "SELECT DISTINCT users_subjects.subject_code, subjects.subject_name FROM users_subjects, subjects WHERE users_subjects.username = 'cat' AND users_subjects.subject_code = subjects.subject_code ORDER BY subject_code;"; //Run the Query and store the result $mysql_result=mysql_query($sql,$db); echo "<SELECT NAME=\"subject_code\" valign=bottom onChange='document.forms[0].submit()'>"; echo "<OPTION VALUE=\"na\"><font color='grey'> - please select a ubject - </font> "; while ($row=mysql_fetch_array($mysql_result)) { $sub_code=$row["subject_code"]; $sub_title=$row["subject_name"]; // We display the results under the correct headings echo "<OPTION VALUE=\"$sub_code\">$sub_code - $sub_title"; } //print the subject that was selected echo $subject_code; ?> |
|
|||
|
"GC" <gcoyle@dodo.com.au> schreef in bericht news:3f5e9c02@news.comindico.com.au... > below is the code to populate a drop down menu with information from a > database. > > i use the onChange to refresh the page so it can print the slected value to > the screen > "<SELECT NAME=\"subject_code\" valign=bottom > onChange='document.forms[0].submit()'> > however all that happens is that it refreshes, what i am ultimatly is trying > to do is populate a second > dropdown menu using the subject_code to draw the info out of the db > Two things can go wrong here: 1. You didn't define a proper form 2. register_globals are disabled When #2 is the case, form values should be access trhough either the $_POST or $_GET arrays (or $HTTP_POST_VARS or $HTTP_GET_VARS when using PHP version < 4.1). Which you should use is depending on the value of the method attribute in the <form /> tag. ex: <? echo $_POST['subject_code']; ?> JW |
|
|||
|
You could also use JS for that...It looks better cause there's no
submiting.... In one project I had 3 dependable select boxes and JS is perfect for that....there are some good examples on the net.... use google for "dependable select boxes" or something similar.... hope this helps... "Janwillem Borleffs" <jwb@jwbfoto.demon.nl> wrote in message news:3f5f56e4$0$28894$1b62eedf@news.euronet.nl... > > "GC" <gcoyle@dodo.com.au> schreef in bericht > news:3f5e9c02@news.comindico.com.au... > > below is the code to populate a drop down menu with information from a > > database. > > > > i use the onChange to refresh the page so it can print the slected value > to > > the screen > > "<SELECT NAME=\"subject_code\" valign=bottom > > onChange='document.forms[0].submit()'> > > however all that happens is that it refreshes, what i am ultimatly is > trying > > to do is populate a second > > dropdown menu using the subject_code to draw the info out of the db > > > > Two things can go wrong here: > 1. You didn't define a proper form > 2. register_globals are disabled > > When #2 is the case, form values should be access trhough either the $_POST > or $_GET arrays (or $HTTP_POST_VARS or $HTTP_GET_VARS when using PHP version > < 4.1). Which you should use is depending on the value of the method > attribute in the <form /> tag. > > ex: <? echo $_POST['subject_code']; ?> > > > JW > > > |
|
|||
|
Oh I see that Janwillem is "dealing" with your problem...
You're in good hands :))) ......... "point" <point@caanNOSPAMproduction.com> wrote in message news:bjpues02lg@enews4.newsguy.com... > You could also use JS for that...It looks better cause there's no > submiting.... > > In one project I had 3 dependable select boxes and JS is perfect for > that....there are some good examples on the net.... > > use google for "dependable select boxes" or something similar.... > > hope this helps... > > > "Janwillem Borleffs" <jwb@jwbfoto.demon.nl> wrote in message > news:3f5f56e4$0$28894$1b62eedf@news.euronet.nl... > > > > "GC" <gcoyle@dodo.com.au> schreef in bericht > > news:3f5e9c02@news.comindico.com.au... > > > below is the code to populate a drop down menu with information from a > > > database. > > > > > > i use the onChange to refresh the page so it can print the slected value > > to > > > the screen > > > "<SELECT NAME=\"subject_code\" valign=bottom > > > onChange='document.forms[0].submit()'> > > > however all that happens is that it refreshes, what i am ultimatly is > > trying > > > to do is populate a second > > > dropdown menu using the subject_code to draw the info out of the db > > > > > > > Two things can go wrong here: > > 1. You didn't define a proper form > > 2. register_globals are disabled > > > > When #2 is the case, form values should be access trhough either the > $_POST > > or $_GET arrays (or $HTTP_POST_VARS or $HTTP_GET_VARS when using PHP > version > > < 4.1). Which you should use is depending on the value of the method > > attribute in the <form /> tag. > > > > ex: <? echo $_POST['subject_code']; ?> > > > > > > JW > > > > > > > > |