我试图存储查询结果,以便在另一个SELECT语句中使用它,但它没有工作..
$username = $_SESSION['username'];
$result = "SELECT sensorid FROM users WHERE username = '$username' ";
$ result应该有一个整数,但是如何将该变量用于另一个选择,如...
$sql = "SELECT * FROM sensor WHERE sensorid = '$result'";
答案 0 :(得分:0)
您需要在sensorid列上将用户表与传感器表连接起来。
$query = "select s.* from users u join sensor s on s.id = u.sensorid where u.username = $username"
请参阅this