This topic is locked

Trying To Get Information From One Table

1/23/2013 8:00:58 AM
PHPRunner General questions
S
swanside author

Hello.

I have these tables

--

-- Table structure for table `account`

--
CREATE TABLE IF NOT EXISTS `account` (

`Engineer_Note` varchar(50) DEFAULT NULL,

`Telephone` varchar(50) DEFAULT NULL,

`EngineerId` int(11) NOT NULL AUTO_INCREMENT,


And

--

-- Table structure for table `labour`

--
CREATE TABLE IF NOT EXISTS `labour` (

`Job_No` varchar(50) NOT NULL,

`Paying_Rate` double DEFAULT NULL,

`EngineerId` int(10) NOT NULL DEFAULT '0',


I have this snippet in my project.

global $conn;

$sql = "select EngineerId from labour where job_no='".postvalue("editid1")."'";

$rs = db_query($sql,$conn);

$data = db_fetch_array($rs);

if(!$data)

return;

echo "<table>";

while(1)

{

echo "<tr>";

foreach($data as $v)

{

echo "<td>";

echo htmlspecialchars($v);

echo "</td>";

}

echo "</tr>";

if(!($data = db_fetch_array($rs)))

break;

}

echo "</table>";



This displays the ID of the engineer, but I need to display the Engineers name from another table,

So I have tried this

global $conn;

$sql = "select `Engineer_Note` FROM `account` WHERE 'account.EngineerId' = 'labour.EngineerId' and 'labour.Job_No='".postvalue("editid1")."'";

$rs = db_query($sql,$conn);

$data = db_fetch_array($rs);

if(!$data)

return;

echo "<table>";

while(1)

{

echo "<tr>";

foreach($data as $v)

{

echo "<td>";

echo htmlspecialchars($v);

echo "</td>";

}

echo "</tr>";

if(!($data = db_fetch_array($rs)))

break;

}

echo "</table>";


I have tried various ways in SQL but, I just can not figure it out.

Can somebody please help?

Cheers

Paul

S
swanside author 1/23/2013



http://www.w3schools.com/sql/sql_join.asp



Cheers mate.

I looked at that site initially, but not that far into it.

Many thanks

Paul.