View Full Version : help required for php n mysql
sukanya.paul
03-20-2007, 07:43 AM
I am very new in php and mysql and am stuck at a point in my project.i am explaining my problem:
i have a table called job which has the following fields
id
jobcode
subject
description
postdate
lastdate
opening
url
i want to import data from this table such the subject(which is the 2nd col of the row ,id wont be imported) is a link to another page which is the url. the rows in the table keep increasing as data is stored in the database.
if u could help me out i will be really greatful.
thanks in advance..suk
codeexploiter
03-20-2007, 08:03 AM
Can you rephrase the things you've mentioned in your posting. I don't think I've understood it correctly. According to my understanding you want to retrieve data from a database table.
If you can mentioned what exactly are you trying to achieve people can understand the problem and thus troubleshoot more easily.
sukanya.paul
03-20-2007, 08:20 AM
wht i want is a page whr a table will be displayed with all the fields in the database mentioned..the values in the field subject shud be displayed as a link which whn clicked is directed to the value mentoned in "url" in the database table job.
example:
let the entries in table job of the database be:
id jobcode subject description postdate lastdate opening url
1 sw01 tester jbghv 20/04/07 25/04/07 3 tester.php
the table tht shud be displayed in the front end shud be
jobcode subject lastdate opening
sw01 tester 25/04/07 3
the tester shud be a link to the page tester.php will hv the job description.
as more jobs are entered into the database the front end table shud keep increasing in size
i hv attached the code i hv..its displayin the table but not the subject field..
hope u hv understood the problem and can help me.
thanks
codeexploiter
03-20-2007, 11:03 AM
Try the following 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>";
?>
$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
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.