,所以我想從互連到其他3臺 用戶會選擇$ FAID,將打印數據所需選擇內連接4臺
表1(DBO表4號特定數據.FAID)
FAID(PK)
PCID(FK)
用戶ID(FK)
表2(dbo.users)
用戶ID(PK)
EmployeeName
表3(dbo.SubDeptTransfer)
TransferID(PK)
用戶ID(FK)
SubDeptID(FK)
表4(SubDept)
SubDeptID(PK)
DEPTID(FK)
表5(部門)
DEPTID(PK)
部
<?php
$faidf=$_POST['faidf'];
ini_set("display_errors","on");
$conn = new COM("ADODB.Connection");
try {
$myServer = "WTCPHFILESRV\WTCPHINV";
$myUser = "sa";
$myPass = "[email protected]";
$myDB = "wtcphitinventory";
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
$conn->open($connStr);
if (! $conn) {
throw new Exception("Could not connect!");
}
}
catch (Exception $e) {
echo "Error (File:): ".$e->getMessage()."<br>";
}
if (!$conn)
{exit("Connection Failed: " . $conn);}
echo "<center>";
echo "<table border='0' width ='100%' style='margin-left:90px'><tr><th></th><th></th></tr>";
$sql_exp = "SELECT e.Department
FROM dbo.FA_PC a
INNER JOIN dbo.users b
on a.UserID = b.UserID
INNER JOIN dbo.SubDeptTransfer c
ON a.UserID = c.UserID
INNER JOIN dbo.SubDept d
ON a.SubDeptID = d.SubDeptID
INNER JOIN dbo.department e
ON a.DeptID = e.DeptID
WHERE a.FAID = $faidf";
$rs = $conn->Execute($sql_exp);
echo "<tr><td>".$rs->Fields("Department")."</tr></td>";
$rs->Close();
?>
所有我能得到的是「無效的列名稱SubDeptID」,這是IM肯定的是列名是正確的,雖然我認爲我亂用我的select語句
FAID->用戶 - > subdepttransfer-> subdept - >部門
有多少內部連接已經取得或不能執行超過3個表什麼衝突?如果是的話,有沒有辦法連接5個表格?
有妳數據庫中創建你的表之間的關係 – freaky 2013-02-11 05:29:18
是與他們的外鍵 – Yinks 2013-02-11 05:30:32
沿着互連,因爲你使用的是SQL服務器,我建議你嘗試設計查詢編輯器你的sql服務器。這可以幫助您查詢 – freaky 2013-02-11 05:34:31