我需要显示针对用户表中user_id的表中支持票证。我正在使用MySQLI。这是我写的查询,对我不起作用:
SELECT user_id, subject, message FROM tickets
INNER JOIN users.user_id WHERE user_id='".$user_id."'"
任何人都可以更正此查询吗?
完整代码在这里
<?php
$servername = "localhost";
$username = "d";
$password = "ddds";
$dbname = "sddd";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT user_id, subject, message FROM tickets INNER JOIN users.user_id USING (user_id) WHERE user_id='".$user_id."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table class='table table-bordered'>
<thead>
<tr>
<th>Subject</th>
<th>Date</th>
<th>Status</th>
<th>View</th>
</tr>
</thead>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["subject"]."</td><td>".$row["date"]." ".$row["status"]."</td><td>".$row["view"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
最佳答案
更正的语法:
SELECT T.user_id, T.subject, message FROM tickets T
INNER JOIN users U ON U.user_id = T.user_id WHERE `T.user_id='".$user_id."'"`
您忘记了
ON
。
关于php - PHP帮助内部连接问题mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31648436/