Try the following code
PHP Code:
<?php
class database
{
private $db_handle;
private $user_name;
private $password;
private $data_base;
private $host_name;
private $sql;
private $results;
function __construct($host="localhost",$user,$passwd)
{
$this->db_handle = mysql_connect($host,$user,$passwd);
}
function dbSelect($db)
{
$this->data_base = $db;
if(!mysql_select_db($this->data_base, $this->db_handle))
{
error_log(mysql_error(), 3, "/phplog.err");
die("Error connecting to Database");
}
}
function executeSql($sql_stmt)
{
$this->sql = $sql_stmt;
$this->result = mysql_query($this->sql);
}
function returnResults()
{
return $this->result;
}
}
$user = "root";
$passwd = "";
$db = "newTest";
$sql = "SELECT * FROM JOB ORDER BY jobcode";
$dbObject = new database($host,$user,$passwd);
$dbObject->dbSelect($db);
$dbObject->executeSql($sql);
$res = $dbObject->returnResults();
echo "<table cellspacing='0' cellpadding='0' width='960' border='1'>\n<tr>";
echo "<td width='100'>Job Code</td>";
echo "<td width='6600'>Subject</td>";
echo "<td width='100'>Last Date</td>";
echo "<td width='100'>Opening</td>";
echo "</tr><tr>";
while($record = mysql_fetch_object($res))
{
echo "<td width='100'>".$record->jobcode."</td>";
echo "<td width='660'><a href='".$record->url."'>".$record->subject."</a></td>";
echo "<td width='100'>".$record->lastdate."</td>";
echo "<td width='100'>".$record->opening."</td>";
echo "</tr><tr><td colspan='5'> </td></tr><tr>";
}
echo "</tr></table>";
?>
Code:
$user = "root"; //change this line in the above code with your db user name
$passwd = ""; //change this line in the above code with your db password
$db = "newTest"; //change this line in the above code with your db name
$sql = "SELECT * FROM JOB ORDER BY jobcode"; //change this query if your table name is not JOB
Bookmarks