本文介绍了加入3个表以显示某些数据PHP-MSSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个表,我想获得某些数据供用户查看,并能够POST到其他页

so i have this tables and i want to get certain datas for user to view and be able to POST to other page

我不能张贴图像,所以我有打破这一点,请耐心等待。

i cant post images so i have to break this down so please bear with me

第一页


  • dbo.users

  • pkey(UserID)

  • EmployeeName

第二表


  • dbo.PC

  • pkey(PCID)

  • PC_Number

第三表


  • dbo.FA_PC

  • pkey(FAID)

  • fkey(UserID)

  • fkey / li>
  • dbo.FA_PC
  • pkey(FAID)
  • fkey(UserID)
  • fkey(PCID)

如何以相同的形式显示当前选择的$ rs-> Fields('UserID')的PC_Number,发布到printd.php

how could i display the PC_Number of the currently selected $rs->Fields('UserID') in the same form and still be able to post it on printd.php

我不知道如何连接dbo.users-> dbo.FA_PC-> dbo.PC

i dont know how to connect the dbo.users->dbo.FA_PC->dbo.PC

<form action="printd.php" method="post" target="_blank">
<?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='empt'>";
   while (!$rs->EOF) {
       set_time_limit(0);
        echo "<option value=".$rs->Fields('UserID')." >".$rs->Fields('EmployeeName')."</option>";

      $rs->MoveNext();
   }       
   $rs->Close();   



       ?>


推荐答案



the join will look like this,

SELECT  a.*, c.PC_Number
FROM    users a
        INNER JOIN FA_PC b
            ON a.UserID = b.UserID
        INNER JOIN PC c
            ON b.PCID = c.PCID


$ b b

要完全获得关于联接的知识,请访问以下链接:

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



  • Visual Representation of SQL Joins

这篇关于加入3个表以显示某些数据PHP-MSSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:37