Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP/JavaScript网站中的错误:注意:尝试访问null类型值的数组偏移量_Php - Fatal编程技术网

PHP/JavaScript网站中的错误:注意:尝试访问null类型值的数组偏移量

PHP/JavaScript网站中的错误:注意:尝试访问null类型值的数组偏移量,php,Php,我很累,很沮丧,但我并没有放弃,我已经尝试了所有的东西,从一个字一个字的教程仍然不起作用。我已经试着修复了2天,我已经重新编写了整个代码和所有东西,但仍然无法修复它。我不知道发生了什么事。必须有一个解决办法。我正在学习的教程视频做了完全相同的事情,它工作了! 错误行是:$style=$row['opened']='no'?背景色:DDEDFF;: public function getConvosDropdown($data, $limit) { $page = $data['page

我很累,很沮丧,但我并没有放弃,我已经尝试了所有的东西,从一个字一个字的教程仍然不起作用。我已经试着修复了2天,我已经重新编写了整个代码和所有东西,但仍然无法修复它。我不知道发生了什么事。必须有一个解决办法。我正在学习的教程视频做了完全相同的事情,它工作了! 错误行是:$style=$row['opened']='no'?背景色:DDEDFF;:

public function getConvosDropdown($data, $limit) {

    $page = $data['page'];
    $userLoggedIn = $this->user_obj->getUsername();
    $return_string = "";
    $convos = array();

    if($page == 1)
        $start = 0;
    else 
        $start = ($page - 1) * $limit;

    $set_viewed_query = mysqli_query($this->con, "UPDATE messages SET viewed='yes' WHERE user_to='$userLoggedIn'");

    $query = mysqli_query($this->con, "SELECT user_to, user_from FROM messages WHERE user_to='$userLoggedIn' OR user_from='$userLoggedIn' ORDER BY id DESC");

    while($row = mysqli_fetch_array($query)) {
        $user_to_push = ($row['user_to'] != $userLoggedIn) ? $row['user_to'] : $row['user_from'];

        if(!in_array($user_to_push, $convos)) {
            array_push($convos, $user_to_push);
        }
    }

    $num_iterations = 0; //Number of messages checked 
    $count = 1; //Number of messages posted

    foreach($convos as $username) {

        if($num_iterations++ < $start)
            continue;

        if($count > $limit)
            break;
        else 
            $count++;


        $is_unread_query = mysqli_query($this->con, "SELECT opened FROM messages WHERE user_to='$userLoggedIn' AND user_from='$username' ORDER BY id DESC");
        $row = mysqli_fetch_array($is_unread_query);
        $style = ($row['opened'] == 'no') ? "background-color: #DDEDFF;" : "";


        $user_found_obj = new User($this->con, $username);
        $latest_message_details = $this->getLatestMessage($userLoggedIn, $username);

        $dots = (strlen($latest_message_details[1]) >= 12) ? "..." : "";
        $split = str_split($latest_message_details[1], 12);
        $split = $split[0] . $dots; 

        $return_string .= "<a href='messages.php?u=$username'> 
                            <div class='user_found_messages' style='" . $style . "'>
                            <img src='" . $user_found_obj->getProfilePic() . "' style='border-radius: 5px; margin-right: 5px;'>
                            " . $user_found_obj->getFirstAndLastName() . "
                            <span class='timestamp_smaller' id='grey'> " . $latest_message_details[2] . "</span>
                            <p id='grey' style='margin: 0;'>" . $latest_message_details[0] . $split . " </p>
                            </div>
                            </a>";
    }


    //If posts were loaded
    if($count > $limit)
        $return_string .= "<input type='hidden' class='nextPageDropdownData' value='" . ($page + 1) . "'><input type='hidden' class='noMoreDropdownData' value='false'>";
    else 
        $return_string .= "<input type='hidden' class='noMoreDropdownData' value='true'> <p style='text-align: center;'>No more messages to load!</p>";

    return $return_string;
}

您在哪里设置$row?问题是它的值是空的。你能发布整个函数吗?我刚刚更新了它。在Mysql表中,我给了'opened'varchar3值,是或否。@boahancockash var_dump$is_unread_query;给你什么?显然,在您指定的行之后