如果文件不存在,我正在尝试在查询中添加默认图像。当查询没有while循环时我成功了。但是因为我需要循环这个值。我想将默认图像添加到查询中。
我不会收到任何错误,它只是从我的数据库中打印出一些随机信息。
function fetch_tweets($uid){
$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;
$tweet['profile_img'] = (file_exists("img/{$uid}.jpg")) ?
"img/{$uid}.jpg" : "img/default.jpg" ;
}
return $tweet;
}