dongxun6458 2014-04-15 01:25
浏览 495
已采纳

注意:未定义的属性:第134行的C:\ wamp \ www \ social \ includes \ class-query.php中的stdClass :: $ 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;
?>
  • 写回答

1条回答 默认 最新

  • duanji9264 2014-04-15 01:44
    关注

    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); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!