php - PHP帮助内部连接问题mysqli

标签 php mysql

我需要显示针对用户表中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/

相关文章:

php - 如何从数据库获取值并显示在下拉列表中

php mysql 在文本中创建 Facebook 类型用户友谊通知

php - 是否可以覆盖 Subversion HTML 页面?

php - Htaccess 重写规则/a 到/a/b

php - 在网页上显示 SQL 行的问题

PHP、MySqli动态数据库导航

mysql - 根据另一列的字段值选择具有相同列值的行

javascript - 类型错误: tableObj.appendChild不是一个函数

mysql - 通过命令行将某些列从 csv 导入到 mysql

mysql - 将数组数据插入mysql codeigniter 3