Php MySQLI:in_数组无法正常工作

Php MySQLI:in_数组无法正常工作,php,mysql,mysqli,Php,Mysql,Mysqli,我目前正在创建一个演示注册系统,我会注意到,这不是一个作业或家庭作业,我想有添加到购物车被禁用,如果用户已经购买了该项目和该项目只是以前,它反映在数据库中 //current URL of the Page. cart_update.php redirects back to this URL $current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); //Que

我目前正在创建一个演示注册系统,我会注意到,这不是一个作业或家庭作业,我想有添加到购物车被禁用,如果用户已经购买了该项目和该项目只是以前,它反映在数据库中

    //current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

//Query to get item information
$results = $mysqli->query("SELECT * FROM events ORDER BY eventid");// WHERE sort = '$sort' 
$remaining = $mysqli->query("SELECT * FROM orders");
$obj_r = $remaining->fetch_object(); // obj_r means objects remaining

//Query to disable already purchaced items
$QgetSignups = $mysqli->query("SELECT s.eventid, o.status FROM signups s JOIN orders o ON s.orderid = o.orderid WHERE s.userid = $userid AND o.status = 1");            
$signedup = array();

    while($row = mysqli_fetch_assoc($QgetSignups))
    //while($row = $QgetSignups->fetch_array(MYSQLI_NUM))
{
    array_push($signedup,$row["eventid"]);
}

if ($results) { 

    //fetch results set as object and output HTML
    while($obj = $results->fetch_object())
    {
        echo '<div class="product">'; 
        echo '<form method="post" action="cart_update.php">';
        echo '<div class="product-thumb"><img src="images/'.$obj->image.'"></div>';
        echo '<div class="product-content"><h4>'.$obj->name.'</h4>';
        echo '<div class="product-desc">'.$obj->description.'</div>';
        echo '<div class="product-info">';
        echo 'Price: '.$currency.$obj->price.' | ';
        echo 'Items Left: '.$obj->max.' | ';
        echo '<input type="hidden" style="width:20px;height:15px;" type="text" name="product_qty" value="1" size="3" />'; // OLD CODE TO DISPLAY QTY BOX: Qty: <input style="width:20px;height:15px;" type="text" name="product_qty" value="1" size="3" />';

        if($signupAmount[$row['eventid']] >= $row['max'])
        {
            echo '<button class="add_to_cart">Add To Cart</button>';
        }

        if(in_array($row['eventid'],$signedup))
        {
            print_r($signedup);
            //echo '<button DISABLED class="add_to_cart">Add To Cart</button>';
        }
        echo '</div></div>';
        echo '<input type="hidden" name="product_code" value="'.$obj->name.'" />';
        echo '<input type="hidden" name="type" value="add" />';
        echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
        echo '</form>';
        echo '</div>';
    }

}


?>

脚本当前尝试检查所购买的项目是否与表示项目编号的编号eventid匹配。目前为止,我正在尝试将项目编号推入数组,然后使用in_数组进行检查,但如果我在$row=mysqli_fetch_assoc$QgetSignups提取数组编号时使用该方法,in_数组将不起作用,但是in_数组没有正确地检查它是否存在,如果我使用//while$row=$QgetSignups->fetch_arrayMYSQLI_NUM,array_push不会收集值,但是in_数组方法会尝试显示数组,尽管它是空的。

您没有在当前while循环中迭代下面代码所在的$row

if (in_array($row['eventid'], $signedup)) {
    print_r($signedup);
    //echo '<button DISABLED class="add_to_cart">Add To Cart</button>';
}
我不确定数据库架构是如何设置的,但可能应该是以下内容:

if (in_array($obj->eventid, $signedup)) {
    print_r($signedup);
    //echo '<button DISABLED class="add_to_cart">Add To Cart</button>';
}

在当前while循环中,您没有迭代下面代码所在的$row

if (in_array($row['eventid'], $signedup)) {
    print_r($signedup);
    //echo '<button DISABLED class="add_to_cart">Add To Cart</button>';
}
我不确定数据库架构是如何设置的,但可能应该是以下内容:

if (in_array($obj->eventid, $signedup)) {
    print_r($signedup);
    //echo '<button DISABLED class="add_to_cart">Add To Cart</button>';
}

你是个救生员。这就是确切的解决方案:。一个星期以来我都快发疯了。很高兴我能帮上忙。快乐编码!你是个救生员。这就是确切的解决方案:。一个星期以来我都快发疯了。很高兴我能帮上忙。快乐编码!此外,您几乎应该始终使用in_array$array$value,true的第三个参数;当你可以的时候,让它做一个严格的比较。我以前在没有将in_数组设置为strict时遇到过一些非常奇怪的问题;当你可以的时候,让它做一个严格的比较。我以前在in_数组中遇到过一些非常奇怪的问题,当时没有将其设置为strict。