當我的數據庫行爲空時,我收到了這個令人討厭的錯誤, 但是行應該是空的,直到我爲它添加一些值。 任何線索怎麼回事?我試圖通過在變量前添加@來禁用該問題,但在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;
}
IC,實際上,我雖然這會工作。它給我的回聲「沒有鳴叫,但錯誤信息仍然存在, 可能是因爲我用另一個頁面的回聲調用它? 這樣。 <?php echo $ tweet_email。' @'。$ tweet_name?>? – Dymond 2013-04-24 16:13:07
@Dymond是的,那也是。 – Sammitch 2013-04-24 16:27:41