Php 我的if语句不是';t工作不正常

Php 我的if语句不是';t工作不正常,php,if-statement,mysqli,Php,If Statement,Mysqli,其他一切都应该是好的,但我仍然有一个问题,显示其他功能。理论上,我相信一切都会成功。我看了所有的语法,一切看起来都很好,一切都正确地关闭了。我想做的是,如果$\u GET['cat']==1、2或3(这就是我将其设置为数组的原因)是有效的,那么我希望能够仅提取该特定类别,如果不是,那么我希望它将所有类别显示在一起。很像WordPress的功能 <?php include('config.inc.php'); // security check to make sure it's not

其他一切都应该是好的,但我仍然有一个问题,显示其他功能。理论上,我相信一切都会成功。我看了所有的语法,一切看起来都很好,一切都正确地关闭了。我想做的是,如果
$\u GET['cat']==1、2或3
(这就是我将其设置为数组的原因)是有效的,那么我希望能够仅提取该特定类别,如果不是,那么我希望它将所有类别显示在一起。很像WordPress的功能

<?php

include('config.inc.php');
// security check to make sure it's not grabbing anything extra that's not there
$get_cat_id = mysqli_query($mysql_conn, "SELECT `id` FROM `categories`");
$cat_array = array();
while($row = mysql_fetch_assoc($get_cat_id)) {
    $cat_array[] = $row['id'];
}
echo $cat_array[];

// checks to see if it's calling for a specific category
if(isset($_GET['cat']) && ($_GET['cat'] == $cat_array)) {
    $fetch_post_content = mysqli_query($mysql_conn, "SELECT * FROM `posts` WHERE `category_id` = '".$_GET['cat']."' ORDER BY `id` DESC");
    $fetch_category_content = mysqli_query($mysql_conn, "SELECT * FROM `categories` WHERE `id` = '".$_GET['cat']."'");
?>
        <h1 class="category-title"><?= $fetch_category_content->name; ?></h1>
<?php
    while($post_content = mysqli_fetch_object($fetch_post_content)) { ?>
        <article>
            <?php
            // this checks for and grabs the featured image from the database
            if(isset($post_content->img_id)) {
                $fetch_post_image = mysqli_query($mysql_conn, "SELECT * FROM `images` WHERE `id` = '".$post_content->img_id."'");
            ?>
            <img src="<?= $fetch_post_image->url; ?>">
            <?php } ?>

            <h3 class="post-title"><?= $post_content->title; ?></h3>
            <h5 class="post-datetime">Posted on <?= $post_content->date; ?> at <?= $post_content->time; ?></h5>
            <p class="post-content"><?= $post_content->content; ?></p>
            <?php
            // grabs authors name from user database
            $fetch_post_author = mysqli_query($mysql_conn, "SELECT * FROM `users` WHERE `id` = '".$post_content->author_id."'");
            ?>
            <h6 class="post-author">Posted by <?= $fetch_post_author->name; ?></h6>


        </article>

<?php
    // ends while function
    }

// displays all conent for the front page if no specific category is called
} else {
    $fetch_post_content = mysqli_query("SELECT * FROM `posts` ORDER BY `id` DESC");
    while($post_content = mysqli_fetch_object($fetch_post_content)) {
        ?>

        <article>
            <?php
            // this checks for and grabs the featured image from the database
            if(isset($post_content->img_id)) {
                $fetch_post_image = mysqli_query($mysql_conn, "SELECT * FROM `images` WHERE `id` = '".$post_content->img_id."'");
            ?>
            <img src="<?= $fetch_post_image->url; ?>">
            <?php } ?>

            <h3 class="post-title"><?= $post_content->title; ?></h3>
            <h5 class="post-datetime">Posted on <?= $post_content->date; ?> at <?= $post_content->time; ?></h5>
            <p class="post-content"><?= $post_content->content; ?></p>
            <?php
            // grabs authors name from user database
            $fetch_post_author = mysqli_query($mysql_conn, "SELECT * FROM `users` WHERE `id` = '".$post_content->author_id."'");
            ?>
            <h6 class="post-author">Posted by <?= $fetch_post_author->name; ?></h6>


        </article>
        <?php

    }
}


?>

无法将标量变量与数组进行比较。您需要在这里与我们联系:


正如Fred所指出的,在修复mysql和mysqli函数的混合之前,它不会起作用。

你不能将标量变量与数组进行比较。您需要在这里与我们联系:


正如弗雷德所指出的,在修复mysql和mysqli函数的混合之前,它不会起作用。

一方面,你在混合mysql函数
mysql\u fetch\u assoc
这样做会让你失败。你的if语句并没有像你期望的那样工作,但它们工作正常查看。并确保启用了短打开标记;洞察力<代码>一件事就是混合了MySQL函数
mysql\u fetch\u assoc
这样做会让你失败。你的if语句并没有像你期望的那样工作,但它们工作正常查看。并确保启用了短打开标记;洞察力<代码>好笑,那些
l
通常只是站出来抓住我的衣领我更改了代码,但仍然没有做任何更改,我还修复了mysql函数,出于某种原因,我甚至没有注意到这一点。甚至连源代码都没有显示出来。看看PHP是否报告了一个错误。有趣的是,那些
l_
通常只是站出来抓住我的衣领我更改了代码,但仍然没有做任何更改,我还修复了mysql函数,出于某种原因,我甚至没有注意到这一点。甚至连源代码都没有显示出来。查看PHP是否正在报告错误。
if(isset($_GET['cat']) && in_array($_GET['cat'], $cat_array)) {