0

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

4

1 回答 1

0
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:

于 2013-02-08T03:01:52.860 回答