Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果用户没有照片,如何显示默认图像_Php_Row - Fatal编程技术网

Php 如果用户没有照片,如何显示默认图像

Php 如果用户没有照片,如何显示默认图像,php,row,Php,Row,示例:如果用户在我们的数据库中没有照片,则行显示默认照片 我该怎么做请帮帮我 谢谢 $result=mysql\u query($query)或die(mysql\u error()); $rows=mysql\u num\u rows($result); 回声“; 呼应“摄影教师细节”; 如果($rows>0){ while($row=mysql\u fetch\u数组($result)){ 回声“; 回声“; 呼应“教师姓名:”; echo$row['name'],“”; 回应‘老师不:’;

示例:如果用户在我们的数据库中没有照片,则行显示默认照片 我该怎么做请帮帮我 谢谢

$result=mysql\u query($query)或die(mysql\u error());
$rows=mysql\u num\u rows($result);
回声“;
呼应“摄影教师细节”;
如果($rows>0){
while($row=mysql\u fetch\u数组($result)){
回声“;
回声“;
呼应“教师姓名:”;
echo$row['name'],“
”; 回应‘老师不:’; echo$row['teacherno'],“
”; 呼应“父亲的名字:”; echo$row['fathername'],“
”; 回声'; } }否则{ 回显“未找到结果!”; } 回声“”
echo”“;
呼应“摄影教师细节”;
如果($rows>0){
while($row=mysql\u fetch\u数组($result)){
回声“;
如果(isset($row['photo'])和&!empty($row['photo'])){
回声“;
}否则{
回声“;
}
呼应“教师姓名:”;
echo$row['name'],“
”; 回应‘老师不:’; echo$row['teacherno'],“
”; 呼应“父亲的名字:”; echo$row['fathername'],“
”; 回声'; } }否则{ 回显“未找到结果!”; } 回声“;
echo”“;
呼应“摄影教师细节”;
如果($rows>0){
while($row=mysql\u fetch\u数组($result)){
回声“;
如果(isset($row['photo'])和&!empty($row['photo'])){
回声“;
}否则{
回声“;
}
呼应“教师姓名:”;
echo$row['name'],“
”; 回应‘老师不:’; echo$row['teacherno'],“
”; 呼应“父亲的名字:”; echo$row['fathername'],“
”; 回声'; } }否则{ 回显“未找到结果!”; } 回声“;
尝试执行以下操作:

echo "<img src=images/". $row['photo'] === NULL ? "default_img" : $row['photo'] .
"width='90' height='90'></a></td>";
echo”“;
尝试执行以下操作:

echo "<img src=images/". $row['photo'] === NULL ? "default_img" : $row['photo'] .
"width='90' height='90'></a></td>";
echo”“;

这似乎不是当前代码的完整部分

但是,如果查询是完整的,我建议删除
die(mysql_error())
,然后在两个echo语句之后尝试以下操作:

 } else {
    echo "<img src='images/default_image.png' width='90' height='90'>";
 }
}其他{
回声“;
}

另外值得注意的是,您有一个终止的
,没有打开的
标签。这是无效的HTML。

这似乎不是当前代码的完整部分

但是,如果查询是完整的,我建议删除
die(mysql_error())
,然后在两个echo语句之后尝试以下操作:

 } else {
    echo "<img src='images/default_image.png' width='90' height='90'>";
 }
}其他{
回声“;
}

另外值得注意的是,您有一个终止的
,没有打开的
标签。这不是有效的HTML。

只需检查
$row['photo']
是否为空或包含字符串。如果我们得到一个匹配,那么用户有一个图像,否则,我们可以输出默认图像。下面是一个很好的示例

代码

if (!empty($row['photo']) AND isset($row['photo'])){
    // Image is not empty and there is data contained within the array value
    echo "<img src='images/" . $row['photo'] . "' width='90' height='90' />";
} else {
    // There is no data contained within the value, show the default image
    echo "<img src='images/default_image.png' width='90' height='90' />";
}
if(!empty($row['photo'])和isset($row['photo'])){
//图像不是空的,并且数组值中包含数据
回声“;
}否则{
//值中不包含任何数据,请显示默认图像
回声“;
}
发生了什么事?

使用
empty()
我们使用它来确定字符串(或数组)是否为空,如果为空,则返回
FALSE
isset()
检查变量是否已设置,如果未设置,则返回
FALSE

--剪断--
用户更改了问题,答案更改。

只需检查
$row['photo']
是否为空或包含字符串。如果我们得到一个匹配,那么用户有一个图像,否则,我们可以输出默认图像。下面是一个很好的示例

代码

if (!empty($row['photo']) AND isset($row['photo'])){
    // Image is not empty and there is data contained within the array value
    echo "<img src='images/" . $row['photo'] . "' width='90' height='90' />";
} else {
    // There is no data contained within the value, show the default image
    echo "<img src='images/default_image.png' width='90' height='90' />";
}
if(!empty($row['photo'])和isset($row['photo'])){
//图像不是空的,并且数组值中包含数据
回声“;
}否则{
//值中不包含任何数据,请显示默认图像
回声“;
}
发生了什么事?

使用
empty()
我们使用它来确定字符串(或数组)是否为空,如果为空,则返回
FALSE
isset()
检查变量是否已设置,如果未设置,则返回
FALSE

--剪断--
用户更改了问题,答案更改。

不工作亲爱的22.jpg width='90'height='90'>在我的页面上是这样显示的。你合上字符串了吗?实际上,你应该有“我不能,因为我是新用户,不能编辑<6个字符不工作亲爱的22.jpg width='90'height='90'>我的页面上显示的是这样的你合上字符串了吗?你实际上应该有“我不能,因为我是新用户,不能编辑<6个字符我已经给出了你所要求的解决方案..如果你有更多的查询,用你的查询提出一个新问题..你没有形成好问题,你要求图像,在实现上述代码后,图像会出现,但可能您的其他参数是空的,所以使用
isset()
empty()
函数作为name、tecaherno、父名,就像我为
$row['photo']
所做的那样。我已经给出了您所要求的解决方案。如果您有更多疑问,在你的查询中提出一个新问题。你没有很好地形成问题,你要求图像,在实现上述代码后,图像将出现,但可能是你的其他参数为空,因此使用
isset()
empty()
函数作为name、tecaherno、父名称,就像我对
$row['photo']所做的那样
。你能在我的代码中编辑吗?因为我很困惑。我为你更新了答案。请检查。既然你已经更新了你的问题,请选择下面的解决方案。将图像
echo
替换为其中一个。您可以编辑到我的代码中吗?因为我已为您更新了答案。请检查。由于您已更新了问题,请选择下面的解决方案。用其中一个替换图像
echo
if (!empty($row['photo']) AND isset($row['photo'])){
    // Image is not empty and there is data contained within the array value
    echo "<img src='images/" . $row['photo'] . "' width='90' height='90' />";
} else {
    // There is no data contained within the value, show the default image
    echo "<img src='images/default_image.png' width='90' height='90' />";
}