我必須讓這個代碼返回相同的結果,但只有在用戶ID是一個數字(例如16); 每個設備在此表中都有一個用戶標識和一個用戶名。 這是代碼:PHP&MySQL,獲取表
<?php
$myQuery= 'SELECT * FROM devicesissued di LEFT JOIN usercred uc ON di.userID = uc.userID WHERE 1 ORDER BY timeStamp DESC';
$result = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());
while($row = mysql_fetch_array($result))
{
$catQuery = 'SELECT * FROM deviceinventory WHERE deviceID = '. $row['deviceID'];
$catResult = mysql_query($catQuery) or die($catQuery."<br/><br/>".mysql_error());
$cat = mysql_fetch_array($catResult);
echo "<tr>";
echo "<td>" . $row['displayName'] . "</td>";
echo "<td>" . $row['deviceID'] . "</td>";
echo "<td>" . $cat['barCodeID'] . "</td>";
echo "<td>" . $cat['category'] . "</td>";
echo "<td>" . $row['deviceName'] . "</td>";
echo "<td>" . $cat['operatingSystem'] . "</td>";
echo "<td>" . $cat['serialNumber'] . "</td>";
echo "<td>" . $cat['macAddress'] . "</td>";
echo "<td>" . $row['timeStamp'] . "</td>";
echo "</tr>";
}
?>
如果我添加了WHERE 'userID' = A-Number
條款它不會做任何事情。
如果您有任何想法,我會很樂意嘗試。
謝謝。
'mysql' extension ='bad idea' ... – Hackerman
'WHERE 1 ORDER'why'1' here? – Thamaraiselvam
你真的用引號加'WHERE'userID'嗎?這意味着您將字符串與ID進行比較,而不是列值。查詢應該是'SELECT * FROM devicesissued di LEFT JOIN usercred uc ON di.userID = uc.userID WHERE uc.userId = 16 ORDER BY timeStamp DESC' – Finwe