注意:未定义的属性:C:\wamp\www\social\includes\class-query.php 中的 stdClass::$user_id 第 134 行 [英] Notice: Undefined property: stdClass::$user_id in C:\wamp\www\social\includes\class-query.php on line 134

查看:43
本文介绍了注意:未定义的属性:C:\wamp\www\social\includes\class-query.php 中的 stdClass::$user_id 第 134 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每次尝试查看我的时间提要时都会出现此错误.我不知道代码有什么问题.有人可以帮忙吗?我的代码如下.将首先添加第 134 行,然后添加其余代码

公共函数 do_news_feed($user_id) {$status_objects = $this->get_status_objects($user_id);foreach ( $status_objects as $status ) {?><div class="status_item">第 134 行 -----><?php $user = $this->load_user_object($status->user_id);?><h3><a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename;?></a></h3><p><?php echo $status->status_content;?></p>

<?php}}

完整代码

select($query);如果(!$obj){返回未找到用户";}返回 $obj[0];}公共函数 load_all_user_objects() {全球 $db;$table = 's_users';$查询 = "SELECT * FROM $table";$obj = $db->select($query);如果(!$obj){返回未找到用户";}返回 $obj;}公共函数 get_friends($user_id) {全球 $db;$table = 's_friends';$查询 = "SELECT ID,friend_id FROM $tableWHERE user_id = '$user_id'";$friends = $db->select($query);foreach ( $friends 作为 $friend ) {$friend_ids[] = $friend->friend_id;}返回 $friend_ids;}公共函数 get_status_objects($user_id) {全球 $db;$table = 's_status';$friend_ids = $this->get_friends($user_id);如果(!空($friend_ids)){array_push($friend_ids, $user_id);} 别的 {$friend_ids = array($user_id);}$accepted_ids = implode(', ', $friend_ids);$查询 = "SELECT * FROM $tableWHERE user_id IN ($accepted_ids)ORDER BY status_time DESC";$status_objects = $db->select($query);返回 $status_objects;}公共函数 get_message_objects($user_id) {全球 $db;$table = 's_messages';$查询 = "SELECT * FROM $tableWHERE message_recipient_id = '$user_id'";$messages = $db->select($query);返回 $messages;}公共函数 do_user_directory() {$users = $this->load_all_user_objects();foreach ( $users as $user ) { ?><div class="directory_item"><h3><a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename;?></a></h3><p><?php echo $user->user_email;?></p>

<?php}}公共函数 do_friends_list($friends_array) {foreach ( $friends_array 作为 $friend_id ) {$users[] = $this->load_user_object($friend_id);}foreach ( $users as $user ) { ?><div class="directory_item"><h3><a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename;?></a></h3><p><?php echo $user->user_email;?></p>

<?php}}公共函数 do_news_feed($user_id) {$status_objects = $this->get_status_objects($user_id);foreach ( $status_objects as $status ) {?><div class="status_item"><?php $user = $this->load_user_object($status->user_id);?><h3><a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename;?></a></h3><p><?php echo $status->status_content;?></p>

<?php}}公共函数 do_inbox($user_id) {$message_objects = $this->get_message_objects($user_id);foreach ( $message_objects as $message ) {?><div class="status_item"><?php $user = $this->load_user_object($message->message_sender_id);?><h3>来自:<a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename;?></a></h3><p><?php echo $message->message_subject;?></p><p><?php echo $message->message_content;?></p>

<?php}}}}$query = 新查询;?>

解决方案

只需将 user_id 更改为 user_ID 即可.不要忘记 php 区分大小写

将行 134 更改为

load_user_object($status->user_ID);?>

Im having this error showing up every time I try to view my time feed. I dont know whats wrong with the code. Can someone help? My code is below. Line 134 will be added first, then the rest of the code

public function do_news_feed($user_id) {
                $status_objects = $this->get_status_objects($user_id);

                foreach ( $status_objects as $status ) {?>
                    <div class="status_item">
    Line 134 ----->  <?php $user = $this->load_user_object($status->user_id); ?>
                        <h3><a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename; ?></a></h3>
                        <p><?php echo $status->status_content; ?></p>
                    </div>
                <?php
                }
            }

The Full code

<?php
    require_once('class-db.php');

    if ( !class_exists('QUERY') ) {
        class QUERY {
            public function load_user_object($user_id) {
                global $db;

                $table = 's_users';

                $query = "
                                SELECT * FROM $table
                                WHERE ID = $user_id
                            ";

                $obj = $db->select($query);

                if ( !$obj ) {
                    return "No user found";
                }

                return $obj[0];
            }

            public function load_all_user_objects() {
                global $db;

                $table = 's_users';

                $query = "
                                SELECT * FROM $table
                            ";

                $obj = $db->select($query);

                if ( !$obj ) {
                    return "No user found";
                }

                return $obj;
            }

            public function get_friends($user_id) {
                global $db;

                $table = 's_friends';

                $query = "
                                SELECT ID, friend_id FROM $table
                                WHERE user_id = '$user_id'
                            ";

                $friends = $db->select($query);

                foreach ( $friends as $friend ) {
                    $friend_ids[] = $friend->friend_id;
                }

                return $friend_ids;
            }

            public function get_status_objects($user_id) {
                global $db;

                $table = 's_status';

                $friend_ids = $this->get_friends($user_id);

                if ( !empty ( $friend_ids ) ) {
                    array_push($friend_ids, $user_id);
                } else {
                    $friend_ids = array($user_id);
                }

                $accepted_ids = implode(', ', $friend_ids);

                $query = "
                                SELECT * FROM $table
                                WHERE user_id IN ($accepted_ids)
                                ORDER BY status_time DESC
                            ";

                $status_objects = $db->select($query);

                return $status_objects;
            }

            public function get_message_objects($user_id) {
                global $db;

                $table = 's_messages';

                $query = "
                                SELECT * FROM $table
                                WHERE message_recipient_id = '$user_id'
                            ";

                $messages = $db->select($query);

                return $messages;
            }

            public function do_user_directory() {
                $users = $this->load_all_user_objects();

                foreach ( $users as $user ) { ?>
                    <div class="directory_item">
                        <h3><a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename; ?></a></h3>
                        <p><?php echo $user->user_email; ?></p>
                    </div>
                <?php
                }
            }

            public function do_friends_list($friends_array) {
                foreach ( $friends_array as $friend_id ) {
                    $users[] = $this->load_user_object($friend_id);
                }

                foreach ( $users as $user ) { ?>
                    <div class="directory_item">
                        <h3><a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename; ?></a></h3>
                        <p><?php echo $user->user_email; ?></p>
                    </div>
                <?php
                }
            }

            public function do_news_feed($user_id) {
                $status_objects = $this->get_status_objects($user_id);

                foreach ( $status_objects as $status ) {?>
                    <div class="status_item">
                        <?php $user = $this->load_user_object($status->user_id); ?>
                        <h3><a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename; ?></a></h3>
                        <p><?php echo $status->status_content; ?></p>
                    </div>
                <?php
                }
            }

            public function do_inbox($user_id) {
                $message_objects = $this->get_message_objects($user_id);

                foreach ( $message_objects as $message ) {?>
                    <div class="status_item">
                        <?php $user = $this->load_user_object($message->message_sender_id); ?>
                        <h3>From: <a href="/social/profile-view.php?uid=<?php echo $user->ID; ?>"><?php echo $user->user_nicename; ?></a></h3>
                        <p><?php echo $message->message_subject; ?></p>
                        <p><?php echo $message->message_content; ?></p>
                    </div>
                <?php
                }
            }
        }
    }

    $query = new QUERY;
?>

解决方案

just change user_id to user_ID . don't forget php is case sensitive

change line 134 to

<?php $user = $this->load_user_object($status->user_ID); ?>

这篇关于注意:未定义的属性:C:\wamp\www\social\includes\class-query.php 中的 stdClass::$user_id 第 134 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆