You could use a if/while construct. Something like:

<select name=\"courses\">
if ($_POST['studentselect']){
$result = mysql_query("SELECT courses FROM students WHERE student_name =
'" . $_POST['studentselect'] . "'");

while ($row = mysql_fetch_assoc($result))
    echo "<option value=".$row['course'].">".$row['course']."</option>";

Basically you would submit the form, and if a student was selected, it
would populate the list with their courses from the database.


----- Original message -----
From: "G. Cohen" <[EMAIL PROTECTED]>
Date: Sun, 18 Jul 2004 19:30:49 +0300
Subject: [PHP-DB] php, javascript and db - your help is needed


I have a HTML form with 2 select boxes, lets say students and courses.
the from loads for the first time, I fill the students select box with
from database. The courses selectbox remains empty.
When the user selects a value from the students selectbox (onchange
I should go to the db to reterive the courses for the selected student
fill the courses selectbaox. I found it very complicated to do the
interaction between javascript and php: apparently, I have to submit the
from for the selected student id to be passed as a parameter to php (so
php can access the db with the student id and retrieve his courses), and
the same time I want the form to stay with the list of students, and the
selected student. This should not be that hard, should it?! this is
something trivial, I hope?
I also tried using cookies, with no success.
If someone knows how to do that, please let me know.

Best Regards,
G. Cohen

PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to