这是我的代码:

$query2 = mysql_query("SELECT * FROM categories WHERE parent = $id JOIN SELECT * FROM posts WHERE main_nav_page = '$idTwo'");

                    while ($row2 = mysql_fetch_assoc($query2)) {
                        $id   = $row2['id'];
                        $name = $row2['name'];
                        $slug = $row2['slug'];
                        $subMenuOrder = $row2['sub_menu_order'];

                        echo "<tr>\n";
                        echo "<td>&nbsp; -- $name</td>\n";
                        echo "</tr>\n";
                    }


我的语法错误吗?

编辑:

错误消息是:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/studentw/public_html/new_nav.php on line 30

最佳答案

与其相反,您可能想要更多类似的东西:

SELECT *
FROM
       categories c
    INNER JOIN
       posts p ON c.categoryid = p.categoryid
WHERE
       c.parent = $id
       AND p.main_nav_page = '$idTwo';


请注意,表是联接的,而不是select语句。另外,联接在FROM子句中指定。

尝试这个:

$results = mysql_query("query here") or die(mysql_error());

10-08 07:17