douci6541 2013-02-08 02:59
浏览 48

选择3个表的语句

So i have a php program in which i should be able to print the variable

table 1
dbo.FA_PC(table name)
FAID(PK)
PCID (FK)
UserID(FK)

table 2
dbo.users(table name)
UserID(PK)
BranchID(FK)
Employeename

table 3 dbo.Branch(table name)
BranchID(PK)
Branchname

<?php
$faid=$_POST['faid'];
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);}
  echo "<center>";
   echo "<table border='0' width ='100%' style='margin-left:90px'><tr><th></th><th></th></tr>";
   $sql_exp = "select * from dbo.users inner join dbo.FA_PC on dbo.userd.UserID = dbo.FA_PC.UseriD WHERE FAID = $faidf";    
   $rs = $conn->Execute($sql_exp);  

    echo "<tr><td>PC Number:".$rs->Fields("Employeename")."</td>";
?>  

what i want to do is when FAID is selected is could post the Branchname of the FAID selected

  • 写回答

1条回答 默认 最新

  • dpl74687 2013-02-08 03:01
    关注
    SELECT  a.*, b.*, c.*  // select columns you want
    FROM    users a
            INNER JOIN FA_PC b
                ON a.userID = b.UserID
            INNER JOIN Branch c
                ON a.BranchID = c.BranchID
    WHERE   b.FAID = 'valueHere'
    

    To fully gain knowledge about joins, kindly visit the link below:

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog