0

可能重复:
加入 3 个表以显示某些数据 PHP-MSSQL

我有这些表,我想获取某些数据供用户查看并能够发布到其他页面

我不能发布图片,所以我必须分解它,所以请多多包涵

1st table     
 - dbo.users
 - pkey(UserID)
 - EmployeeName

2nd table    
 - dbo.PC
 - pkey(PCID)
 - PC_Number

3rd table
 - dbo.FA_PC    
 - pkey(FAID)
 - fkey(UserID)
 - fkey(PCID)

<?php
ini_set("display_errors","on");
$conn = new COM("ADODB.Connection");
try {
    $myServer = "WTCPHFILESRV\WTCPHINV";
    $myUser = "sa";
    $myPass = "P@ssw0rd";
    $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);
}

$sql_exp = "select * from dbo.users";
$rs = $conn->Execute($sql_exp);
echo "<select name='empf'>";
while (!$rs->EOF) {
    set_time_limit(0);
    echo "<option value=".$rs->Fields('UserID')." >".$rs->Fields('EmployeeName')."</option>";
    $rs->MoveNext();
}
$rs->Close();
?>

我怎样才能以相同的形式显示PC_Number当前选择的内容$rs->Fields('UserID'),并且仍然能够将其发布在 printd.php 上

4

1 回答 1

0

尝试内部联接

select A.*,B.*,C.* from table1 A INNER JOIN Table2 B ON A.userid=B.userid 
INNER JOIN table3 C ON C.pcid=B.pcid where A.userid='2'

祝你好运

于 2013-01-31T06:20:26.717 回答