Hi Guys,
I'm currently querying a database to display contents in drop-down list using the code below:
<?
$connection = mysql_connect("localhost","root","password"
or die("Couldn't make connection."
$db = mysql_select_db("database", $connection)
or die("Couldn't select database."
$sql = "SELECT DISTINCT code, title FROM modules ORDER BY code ASC";
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query."
while ($row = mysql_fetch_array($sql_result)) {
$code = $row["code"];
$title = $row["title"];
if ($curr_code == $code) {
$option_block .= "<OPTION value=\"$code\" selected>$code - $title</OPTION>";
} else {
$option_block .= "<OPTION value=\"$code\">$code - $title</OPTION>";
}
}
?>
<FORM method=post" action="courses.php">
<P>Course Code:<br>
<SELECT name="code">
<? echo "$option_block"; ?>
</SELECT>
<P><INPUT type="submit" value="submit"></p>
</FORM>
where code and title are fields in my database.
The two fields currently reside in the table "modules".
When the user clicks on the submit button I want another table to be queried ("materials" and all records where the field "code" is the same as the search criteria to be displayed on the same page (under the drop down list).
I've been trying lots of different ways and fail each time.
Any help in doing this or pointers to exisiting scripts would be greatfully received.
Thanks in advance,
Frazer
I'm currently querying a database to display contents in drop-down list using the code below:
<?
$connection = mysql_connect("localhost","root","password"
or die("Couldn't make connection."
$db = mysql_select_db("database", $connection)
or die("Couldn't select database."
$sql = "SELECT DISTINCT code, title FROM modules ORDER BY code ASC";
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query."
while ($row = mysql_fetch_array($sql_result)) {
$code = $row["code"];
$title = $row["title"];
if ($curr_code == $code) {
$option_block .= "<OPTION value=\"$code\" selected>$code - $title</OPTION>";
} else {
$option_block .= "<OPTION value=\"$code\">$code - $title</OPTION>";
}
}
?>
<FORM method=post" action="courses.php">
<P>Course Code:<br>
<SELECT name="code">
<? echo "$option_block"; ?>
</SELECT>
<P><INPUT type="submit" value="submit"></p>
</FORM>
where code and title are fields in my database.
The two fields currently reside in the table "modules".
When the user clicks on the submit button I want another table to be queried ("materials" and all records where the field "code" is the same as the search criteria to be displayed on the same page (under the drop down list).
I've been trying lots of different ways and fail each time.
Any help in doing this or pointers to exisiting scripts would be greatfully received.
Thanks in advance,
Frazer