code to paste:
<?php
$con = mysql_connect("localhost","root","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample", $con);
$result = mysql_query("SELECT * FROM subjectentry order by coursecode");
echo "<table border='1'>
<tr>
<th><b>Coursecode</b></th>
<th><b>Students</b></th>
</tr>";
while($row = mysql_fetch_array($result))
{
$shape = $row['coursecode'];
echo "<tr>";
echo "<td valign='top'><b>" . $row['coursecode'] . "</b></td>";
//Sub query type serves as your data shaping
$resultx = mysql_query("SELECT * FROM subjectlist where coursecode = '$shape' order by completename");
echo "<td>";
while($rowx = mysql_fetch_array($resultx))
{
echo "<p>";
echo $rowx['completename'] . " " . $rowx['address'];
echo "<p>";
}
echo "</td>";
//Sub query type like as your data shaping
echo "</tr>";
}
echo "</table>";
mysql_close($con)
?>
output:
another sample
code to paste:
<?php
$con = mysql_connect("localhost","root","htciton");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("students", $con);
$result = mysql_query("SELECT * FROM subjectentry order by coursecode");
echo "<table border='1'>
<tr>
<th><b>Coursecode</b></th>
<th><b>Students</b></th>
</tr>";
while($row = mysql_fetch_array($result))
{
$shape = $row['coursecode'];
echo "<tr>";
echo "<td valign='top'><b>" . $row['coursecode'] . "</b></td>";
//Sub query type serves as your data shaping
$resultx = mysql_query("SELECT * FROM subjectlist where coursecode = '$shape' order by completename");
echo "<td>";
echo '<table border="1">';
while($rowx = mysql_fetch_array($resultx))
{
echo '<tr>';
echo "<td>";
echo $rowx['completename'] . " " . $rowx['address'];
echo "<td>";
echo '</tr>';
}
echo '</table>';
echo "</td>";
//Sub query type serves as your data shaping
echo "</tr>";
}
echo "</table>";
mysql_close($con)
?>
output:
No comments:
Post a Comment