0

好的,所以如果有人有图片,我有 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">
4

2 回答 2

3

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

$image = $results_row['photo'];
if (empty($image)) $image = "default.png";
<img src="/image/'.$image.'" width="50px" height="40px">
于 2012-07-11T01:49:34.400 回答
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">
于 2012-07-11T01:51:32.047 回答