如何设置默认图像

时间:2012-07-11 01:39:08

标签: php mysql image null default

好的,所以我有sql和输出,如果有人有图像,如果用户没有上传个人资料图片,我将如何重写这个来设置默认图像?

$search = mysql_query("SELECT users.username, users.id, tbl_image.photo, tbl_image.userid FROM users LEFT OUTER JOIN tbl_image ON users.id=tbl_image.userid WHERE users.username LIKE '%$search_term%' and users.business <> 'business'");

<img src="/image/'.$results_row['photo'].'" width="50px" height="40px">

2 个答案:

答案 0 :(得分:3)

如果图像为NULL或“”,则使用默认值:

$image = $results_row['photo'];
if (empty($image)) $image = "default.png";
<img src="/image/'.$image.'" width="50px" height="40px">

答案 1 :(得分:1)

检查它是否为空。如果是,请使用默认照片。

$search = mysql_query("SELECT users.username, users.id, tbl_image.photo, tbl_image.userid FROM users LEFT OUTER JOIN tbl_image ON users.id=tbl_image.userid WHERE users.username LIKE '%$search_term%' and users.business <> 'business'");

$photo = $results_row['photo'] : $results_row['photo'] ? 'default_photo.jpg'

<img src="/image/'.$photo.'" width="50px" height="40px">