HTML/Javascript

SES by business degree online promotion team.

Philippine Airlines International Flight schedules

Philippine Airlines International Flight schedules
Philippine Airlines International Flight schedules

Search This Blog

Wednesday, October 6, 2010

PHP sub query

PHP sub query 1

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:





PHP sub query 2

<?php

$con = mysql_connect("localhost","root","yourpassword");
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>';

?>

output:




No comments:

Post a Comment