-2

这是代码,错误来自哪里 :) 我希望我能尽快得到答案!!!

function getSubs($id, $type, $start = null) {

        if($type == 0) {
            if(is_numeric($start)) {
                if($start == 0) {
                    $start = '';
                } else {
                    $start = 'AND `relations`.`id` < \''.$this->db->real_escape_string($start).'\'';
                }
                $limit = 'LIMIT '.($this->s_per_page + 1);
            }
            $query = sprintf("SELECT * FROM `relations`, `wp_users` WHERE `relations`.`subscriber` = '%s' AND `relations`.`leader` = `wp_users`.`ID` $start ORDER BY `relations`.`id` DESC $limit", $this->db->real_escape_string($id));
        } else {
            if(is_numeric($start)) {
                if($start == 0) {
                    $start = '';
                } else {
                    $start = 'AND `relations`.`id` < \''.$this->db->real_escape_string($start).'\'';
                }
                $limit = 'LIMIT '.($this->s_per_page + 1);
            }
            $query = sprintf("SELECT * FROM `relations`, `wp_users` WHERE `relations`.`leader` = '%s' AND `relations`.`subscriber` = `wp_users`.`ID` $start ORDER BY `relations`.`id` DESC $limit", $this->db->real_escape_string($id));
        }

        $result = $this->db->query($query);
        while($row = $result->fetch_assoc()) {
            $array [] = $row;
        }
        return array($array, $total = $result->num_rows);
    }

    function getActions($id, $likes = null, $type = null) {
        global $LNG;


        if($type == 1) {
            $verify = $this->verifyLike($id);
            $result = $this->db->query(sprintf("SELECT * FROM `messages`, `wp_users` WHERE `id` = '%s' AND `messages`.`uid` = `wp_users`.`ID`", $this->db->real_escape_string($id)));
            if($result->num_rows == 0) {
                return $LNG['like_message_not_exist'];
            }
            if(!$verify) {
                $stmt = $this->db->prepare("INSERT INTO `likes` (`post`, `by`) VALUES ('{$this->db->real_escape_string($id)}', '{$this->db->real_escape_string($this->id)}')");
                $stmt->execute();
                $affected = $stmt->affected_rows;
                $stmt->close();
                if($affected) {
                    $this->db->query("UPDATE `messages` SET `likes` = `likes` + 1, `time` = `time` WHERE id = '{$this->db->real_escape_string($id)}'");
                    $user = $result->fetch_assoc();
                    $insertNotification = $this->db->query(sprintf("INSERT INTO `notifications` (`from`, `to`, `parent`, `type`, `read`) VALUES ('%s', '%s', '%s', '2', '0')", $this->db->real_escape_string($this->id), $user['uid'], $user['id']));
                    if($this->email_like) {
                        if($user['email_like'] && ($this->id !== $user['ID'])) {
                            sendMail($user['user_email'], sprintf($LNG['ttl_like_email'], $this->username), sprintf($LNG['like_email'], realName($user['user_login'], $user['first_name'], $user['last_name']), $this->url.'/index.php?a=profile&u='.$this->username, $this->username, $this->url.'/index.php?a=post&m='.$id, $this->title, $this->url.'/index.php?a=settings&b=notifications'), $this->email);
                        }
                    }
                }
            } else {
                $x = 'already_liked';
            }
        } elseif($type == 2) {
            $verify = $this->verifyLike($id);
            $result = $this->db->query(sprintf("SELECT `id` FROM `messages` WHERE `id` = '%s'", $this->db->real_escape_string($id)));
            if($result->num_rows == 0) {
                return $LNG['like_message_not_exist'];
            }
            if($verify) {
                $stmt = $this->db->prepare("DELETE FROM `likes` WHERE `post` = '{$this->db->real_escape_string($id)}' AND `by` = '{$this->db->real_escape_string($this->id)}'");
                $stmt->execute();
                $affected = $stmt->affected_rows;
                $stmt->close();
                if($affected) {
                    $this->db->query("UPDATE `messages` SET `likes` = `likes` - 1, `time` = `time` WHERE id = '{$this->db->real_escape_string($id)}'");
                    $this->db->query("DELETE FROM `notifications` WHERE `parent` = '{$this->db->real_escape_string($id)}' AND `type` = '2' AND `from` = '{$this->db->real_escape_string($this->id)}'");
                }
            } else {
                $x = 'already_disliked';
            }
        }
    if($likes == null) {
            $query = sprintf("SELECT `likes` FROM `messages` WHERE `id` = '%s'", $this->db->real_escape_string($id));
            $result = $this->db->query($query);
            $get = $result->fetch_row();
            $likes = $get[0];
        }
        $verify = $this->verifyLike($id);
        if($verify) {
            $state = $LNG['dislike'];
            $y = 2;
        } else {
            $state = $LNG['like'];
            $y = 1;
        }
    if($this->l_per_post) {
            $query = sprintf("SELECT * FROM `likes`,`wp_users` WHERE `post` = '%s' and `likes`.`by` = `wp_users`.`ID` ORDER BY `likes`.`id` DESC LIMIT %s", $this->db->real_escape_string($id), $this->db->real_escape_string($this->l_per_post));

            $result = $this->db->query($query);
            while($row = $result->fetch_assoc()) {
                $array[] = $row;
            }
            $people = '';
            foreach($array as $row) {
                $people .= '<a href="'.$this->url.'/index.php?a=profile&u='.$row['user_login'].'"><img src="'.$this->url.'/thumb.php?src='.$row['image'].'&w=25&h=25&t=a" title="'.realName($row['user_login'], $row['first_name'], $row['last_name']).' '.$LNG['liked_this'].'" /></a> ';
            }
        }
$actions = '<a onclick="doLike('.$id.', '.$y.')" id="doLike'.$id.'">'.$state.'</a> - <a onclick="focus_form('.$id.')">'.$LNG['comment'].'</a> - <a onclick="share('.$id.')">'.$LNG['share'].'</a> <div class="like_btn" id="like_btn'.$id.'"> '.$people.$likes.'</div>';

        if(empty($this->id)) {
            $actions = '<a href="'.$this->url.'">'.$LNG['login_to_lcs'].'</a> <div class="like_btn"> '.$people.$likes.'</div>';
        }
        if(isset($x)) {
            return $LNG["$x"].' <div class="like_btn"> '.$likes.'</div>';
        }
        return $actions;
    }
4

1 回答 1

2

“试图获得非对象的财产”的通知再清楚不过了。您正在尝试读取不是对象的东西的属性。

例如:

$object = false;
echo $object->property; // Notice: Trying to get property of non-object

可能它正在发生,因为您假设您正在执行的每个 SQL 查询都是成功的。但是,如果 SQL 查询出现错误并且无法运行,则调用将返回false而不是返回结果对象。

Sinse你甚至没有说你遇到这个问题的线路是不值得在这里进一步帮助你的努力。在尝试使用结果之前检查您的查询是否成功,并从中读取 MySQL 错误消息$this->db->error以找出问题所在。

于 2013-11-03T01:44:16.570 回答