Hi experts,
I have these values in table main:
Class Subject Chapter
[COLOR=”Red”]FSc1 Biology Chapter 1
FSc1 Biology Chapter 2
FSc1 Biology Chapter 3
[COLOR=”Blue”]FSc1 English Lesson 1
FSc1 English Lesson 2
FSc1 English Lesson 3
[COLOR=”SeaGreen”]FSc2 Physics Chapter 1
FSc2 Physics Chapter 2
FSc2 Physics Chapter 3
Following is my code:
[code=php]<?PHP
$con = mysql_connect(“localhost”,”root”,””);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“quiz”, $con);
$dbname=”quiz”;
?>
<html>
<head>
<meta http-equiv=”Content-Language” content=”en-us”>
<meta name=”GENERATOR” content=”Microsoft FrontPage 6.0″>
<meta name=”ProgId” content=”FrontPage.Editor.Document”>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>Class</title>
</head>
<body>
<div align=”center”>
<form method=”POST” action=””>
<table border=”0″ cellpadding=”0″ style=”border-collapse: collapse” width=”100%” id=”table1″>
<tr>
<td width=”78″>Class:</td>
<td width=”196″>
<?PHP
$sql = “Select class from main group by class”;
$result = mysql_query($sql);
if (!$result) {
echo “DB Error, could not list tablesn”;
echo ‘MySQL Error: ‘ . mysql_error();
exit;
}
?>
<p><select size=”1″ name=”class”>
<?PHP
while ($row = mysql_fetch_row($result)) {
echo “<option>{$row[0]}</option>”;
}
mysql_free_result($result);
?>
</select></p></td>
<?PHP
$sql = “Select subject from main group by subject”;
$result = mysql_query($sql);
if (!$result) {
echo “DB Error, could not list tablesn”;
echo ‘MySQL Error: ‘ . mysql_error();
exit;
}
?>
<td width=”238″>Subject:</td>
<td>
<p><select size=”1″ name=”subject”>
<?PHP
while ($row = mysql_fetch_row($result)) {
echo “<option>{$row[0]}</option>”;
}
mysql_free_result($result);
?>
</select></p>
</td>
<?PHP
$sql = “Select chapter from main group by class,subject”;
$result = mysql_query($sql);
if (!$result) {
echo “DB Error, could not list tablesn”;
echo ‘MySQL Error: ‘ . mysql_error();
exit;
}
?>
<td>
Chapter:</td>
<td width=”93″>
<select size=”1″ name=”chapter”>
<?PHP
while ($row = mysql_fetch_row($result)) {
echo “<option>{$row[0]}</option>”;
}
mysql_free_result($result);
?>
</select></td>
</tr>
<tr>
<td width=”78″> </td>
<td width=”196″> </td>
<td width=”238″><input type=”submit” value=”Submit” name=”B1″><input type=”reset” value=”Reset” name=”B2″></td>
<td> </td>
<td> </td>
<td width=”93″> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
What I want is that if I select FSc1 from the List then the other list needs to show subjects from class FSc1 and if I select any subject it needs to show chapters of that subject.
I tried but failed, plz help.
thanks in advance.