看起来像SQL WHERE子句和JOIN不能一起工作

时间:2015-03-11 04:31:50

标签: php mysql sql mysqli

我正在尝试创建一个基本论坛,而我在SQL中只打印一行时遇到问题。这是我的PHP:

<?php
ob_start();

$host = "localhost";
$user = "root";
$pass = "MYPASSWORD";
$db = "MYDB";

$conn = mysqli_connect($host, $user, $pass, $db) or die("cannot connect to database.");

$sql = "SELECT * FROM forum WHERE fid = '{$fid}' JOIN user ON forum.creator=user.id;";
$result = mysqli_query($conn, $sql);

if ($result == true) {  
    while ($row = mysqli_fetch_assoc($result)) { 
        print "<h1>{$title}</h1>";
    }
}
else { 
    print "failed to reach post.";
}

ob_flush();

&GT;

为了帮助我,我相信一切都有效,除了$sql。我启用了ini_set('display_errors',1);,但我没有收到任何错误消息(我自己为else语句做了一些错误消息)。

1 个答案:

答案 0 :(得分:1)

尝试此查询

SELECT * FROM forum JOIN user ON forum.creator=user.id WHERE fid = '{$fid}' ;