/    Sign up×
Community /Pin to ProfileBookmark

Grouped by two Columns

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]

[COLOR=”Blue”]FSc1 English Lesson 1
FSc1 English Lesson 2
FSc1 English Lesson 3[/COLOR]

[COLOR=”SeaGreen”]FSc2 Physics Chapter 1
FSc2 Physics Chapter 2
FSc2 Physics Chapter 3[/COLOR]

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″>&nbsp;</td>
<td width=”196″>&nbsp;</td>
<td width=”238″><input type=”submit” value=”Submit” name=”B1″><input type=”reset” value=”Reset” name=”B2″></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td width=”93″>&nbsp;</td>
</tr>
</table>
</form>
</div>

</body>

</html>[/code]

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.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @nyt1972 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...