当我的数据库行为空时,我收到了这个烦人的错误,但是在我向其中添加一些值之前,这些行应该是空的。任何线索出了什么问题?我试图通过在变量之前添加 @ 来禁用该问题,但是当它们处于 foreach 循环中时这不起作用。
如果我将数据添加到行中,问题就会停止......
有任何想法吗 ?
一些代码。
$tweets = new Tweets();
foreach($tweets->fetch_tweets($_GET['uid']) as $tweet){
@$tweet_name = $tweet['username'];
@$tweet_date= $tweet['date'];
@$tweet_email= $tweet['email'];
}
function fetch_tweets($uid){ /*Mine and users I follow*/
$uid = (int)$uid;
$query = $this->link->query("SELECT user.id,
user.email,
user.username,
tweets.message,
tweets.date,
userdetails.profile_img,
userdetails.firstname,
userdetails.lastname,
following.id, following.user_id,
following.follow_id
FROM user
LEFT JOIN following ON user.id = following.user_id
JOIN userdetails ON user.id = userdetails.user_id
JOIN tweets ON userdetails.user_id = tweets.user_id
WHERE user.id='{$uid}' OR
user.id IN (SELECT follow_id
FROM following
WHERE following.user_id = '{$uid}' ) GROUP BY tweets.date ORDER BY tweets.date DESC "
);
$tweet = array();
while(($row = $query->fetch(PDO::FETCH_ASSOC)) !==FALSE) {
$tweet[] = $row;
} echo $query->rowCount();
return $tweet;
}