newbie help please!!!!!!!!!

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-10-2003
GC
 
Posts: n/a
Default newbie help please!!!!!!!!!

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;

?>


Reply With Quote
  #2 (permalink)  
Old 09-10-2003
Janwillem Borleffs
 
Posts: n/a
Default Re: newbie help please!!!!!!!!!


"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



Reply With Quote
  #3 (permalink)  
Old 09-11-2003
point
 
Posts: n/a
Default Re: newbie help please!!!!!!!!!

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
>
>
>



Reply With Quote
  #4 (permalink)  
Old 09-11-2003
point
 
Posts: n/a
Default Re: newbie help please!!!!!!!!!

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
> >
> >
> >

>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0