<html>
<head></head>
<body>
<?


//@$d = mysql_connect("localhost","your db_username","your_db_password") or die("Can't connect to the database.");
//@mysql_select_db("your_database") or die("Can't select database.");
include_once("/home/abu-jeib/php/connect.php");


// Retrieve the first two records
$q = "select * from class limit 0, 2";
// Or
// $q = "select * from class limit 2";
@$r = mysql_query($q) or die("Can't perform query.");
echo "Here are the first two records in the table: <br>\n";
echo "Name,	Grade<br>\n";
while ($row = mysql_fetch_array($r))
{
	echo ucwords(strtolower($row[name])), ", $row[grade]<br>\n";
}
echo "<hr \>";

// Find the number of records:
$q = "select count(*) from class";
@$r = mysql_query($q) or die("Can't perform query 2.");
$row = mysql_fetch_array($r);
$number_of_records = $row[0];

$k = $number_of_records - 2;

// Retrieve the first two records
$q = "select * from class limit $k, 2";
@$r = mysql_query($q) or die("Can't perform query 3.");
echo "Here are the last two records in the table: <br>\n";
echo "Name,	Grade<br>\n";
while ($row = mysql_fetch_array($r))
{
	echo ucwords(strtolower($row[name])), ", $row[grade]<br>\n";
}
echo "<hr \>";

@mysql_close($d) or die("Can't close the database");

?>
</body>
</html>

