I have to make this code return the same results but only where userID is a number (ex 16); Every device has an userid and an username in this table. This is the code :
<?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>";
}
?>
If I add the WHERE 'userID' = A-Number clause it doesn't do anything.
If you have any ideas I will be glad to try them.
Thank you.
mysqlextension =bad idea...WHERE 1 ORDERwhy1here?SELECT * FROM devicesissued di LEFT JOIN usercred uc ON di.userID = uc.userID WHERE uc.userId = 16 ORDER BY timeStamp DESCWHERE 1in query is optional. It doesn't do anything much. It produces the same effect as without it will produce. Also, like you asked why it should be there, he could remove it to avoid confusions.WHERE 1withWHERE di.userID = A-Numberor if you have any good reason (which I can't imagine to be honest) forWHERE 1you have to sayWHERE 1 AND di.userID = A-Number. And as @Hackerman already said - do yourself a favor and don't usemysqlextension.