Php 如果文件不存在,则回显员工姓名
我正在使用以下代码尝试显示没有个人资料图片的员工记录。配置文件图片都存储在标有id_number.jpg(例如4567.jpg)的图片/文件夹中。如果没有找到照片,我想回显员工的姓名Php 如果文件不存在,则回显员工姓名,php,mysql,Php,Mysql,我正在使用以下代码尝试显示没有个人资料图片的员工记录。配置文件图片都存储在标有id_number.jpg(例如4567.jpg)的图片/文件夹中。如果没有找到照片,我想回显员工的姓名 $ID = $row_Recordset7['ID']; $image = 'pics/' . $ID . '.jpg'; if (!file_exists($image)) { echo $row_Recordset7['Employee_Name']; } 目前,所有员工的名字都会被回音。任何帮助都将不胜感
$ID = $row_Recordset7['ID'];
$image = 'pics/' . $ID . '.jpg';
if (!file_exists($image)) {
echo $row_Recordset7['Employee_Name'];
}
目前,所有员工的名字都会被回音。任何帮助都将不胜感激
mysql_select_db($database_schedule, $schedule);
$query_Recordset7 = "SELECT DISTINCT ID, Employee_Name, Department
FROM unit
ORDER BY Department, Employee_Name";
$Recordset7 = mysql_query($query_Recordset7, $schedule) or die(mysql_error());
$row_Recordset7 = mysql_fetch_assoc($Recordset7);
$totalRows_Recordset7 = mysql_num_rows($Recordset7);
完整代码:
mysql_select_db($database_schedule, $schedule);
$query_Recordset7 = "SELECT DISTINCT schedule.ID, schedule.Employee_Name, schedule.Department FROM schedule ORDER BY schedule.Employee_Name";
$Recordset7 = mysql_query($query_Recordset7, $schedule) or die(mysql_error());
$row_Recordset7 = mysql_fetch_assoc($Recordset7);
$totalRows_Recordset7 = mysql_num_rows($Recordset7);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lookup: Missing Pics</title>
<style type="text/css">
<!--
body,td,th {
font-size: 30px;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" align="center">
<tr>
<td colspan="3" align="center">
<div align="left">
<a href="../.">Home</a>
>Missing Pics
</div>
</td>
</tr>
<tr>
<td align="center">
<div align="left">
<strong>Name </strong>(<?php echo $totalRows_Recordset7 ?>)
</div>
</td>
<td align="center">
<strong>ID</strong>
</td>
</tr>
<?php do { ?>
<tr bgcolor="<?php
if($SSAdv_m1%$SSAdv_change_every1==0 && $SSAdv_m1>0){
$SSAdv_k1++;
}
print $SSAdv_colors1[$SSAdv_k1%count($SSAdv_colors1)];
$SSAdv_m1++;
?>">
<td align="center">
<div align="left">
<a href="../report.php?recordID=<?php echo $row_Recordset7['ID']; ?>">
<?php
$ID = $row_Recordset7['ID'];
$image = '../pics/' . $ID . '.jpg';
if (!file_exists($image)) {
echo $row_Recordset7['Employee_Name'];
}else{
}
?>
</a>
</div>
</td>
<td align="center"> </td>
</tr>
<?php } while ($row_Recordset7 = mysql_fetch_assoc($Recordset7)); ?>
</table>
<br />
<?php echo $totalRows_Recordset7 ?> Total
</body>
</html>
mysql\u select\u db($database\u schedule,$schedule);
$query_Recordset7=“从计划订单中按计划选择不同的计划.ID、计划.Employee_名称、计划.Department”;
$Recordset7=mysql\u query($query\u Recordset7,$schedule)或die(mysql\u error());
$row_Recordset7=mysql_fetch_assoc($Recordset7);
$totalRows\u Recordset7=mysql\u num\u rows($Recordset7);
?>
查找:缺少图片
丢失的图片
名称()
ID
不完全理解你想做什么,但很明显这是类似于:
$ID = $row_Recordset7['ID'];
$image = 'pics/' . $ID . '.jpg';
if (file_exists($image)) {
// if you have a file (it's a photo of an employee?) - show it
echo '<img src="' . $image . '" title="" alt="">';
} else {
// if there's no file - echo name
echo $row_Recordset7['Employee_Name'];
}
$ID=$row_记录集7['ID'];
$image='pics/'$身份证。jpg';
如果(文件_存在($image)){
//如果你有一个文件(这是一张员工的照片?)-展示它
回声';
}否则{
//如果没有文件-回显名称
echo$row_Recordset7['Employee_Name'];
}
不完全理解你想做什么,但很明显这是类似于:
$ID = $row_Recordset7['ID'];
$image = 'pics/' . $ID . '.jpg';
if (file_exists($image)) {
// if you have a file (it's a photo of an employee?) - show it
echo '<img src="' . $image . '" title="" alt="">';
} else {
// if there's no file - echo name
echo $row_Recordset7['Employee_Name'];
}
$ID=$row_记录集7['ID'];
$image='pics/'$身份证。jpg';
如果(文件_存在($image)){
//如果你有一个文件(这是一张员工的照片?)-展示它
回声';
}否则{
//如果没有文件-回显名称
echo$row_Recordset7['Employee_Name'];
}
由于您提供给我和RiggsFolly的所有信息,您必须循环SQL结果以获取所需数据,然后应用条件:
mysql_select_db($database_schedule, $schedule);
$query_Recordset7 = "SELECT DISTINCT ID, Employee_Name, Department
FROM unit
ORDER BY Department, Employee_Name";
$Recordset7 = mysql_query($query_Recordset7, $schedule) or die(mysql_error());
$totalRows_Recordset7 = mysql_num_rows($Recordset7);
while ($row_Recordset7 = mysql_fetch_assoc($Recordset7)) {
$ID = $row_Recordset7['ID'];
$image = '../pics/' . $ID . '.jpg';
if (!file_exists($image)) {
echo $row_Recordset7['Employee_Name'];
}
}
希望能有帮助
PS:请记住,mysql\uuu
是不安全的,你最好用预先准备好的语句来学习PDO
或mysqli\uu
。因为你给我和RiggsFolly的所有信息,你必须循环SQL结果以获得你想要的数据,然后应用条件:
mysql_select_db($database_schedule, $schedule);
$query_Recordset7 = "SELECT DISTINCT ID, Employee_Name, Department
FROM unit
ORDER BY Department, Employee_Name";
$Recordset7 = mysql_query($query_Recordset7, $schedule) or die(mysql_error());
$totalRows_Recordset7 = mysql_num_rows($Recordset7);
while ($row_Recordset7 = mysql_fetch_assoc($Recordset7)) {
$ID = $row_Recordset7['ID'];
$image = '../pics/' . $ID . '.jpg';
if (!file_exists($image)) {
echo $row_Recordset7['Employee_Name'];
}
}
希望能有帮助
PS:请记住,mysql\uuu
是不安全的,你最好用预先准备好的语句学习PDO
或mysqli\uu
。检查$row\u Recordset7['ID']
的内容,然后检查'pics/'$身份证。jpg'代码>实际存在,因此尝试使用绝对路径而不是相对路径。$row_Recordset7['ID'];存在,因为我可以看到所有ID为“存储在pic\文件夹中”的员工姓名,但每次在新代码中使用数据库扩展时,您都会查看“pics/…”,它已被弃用多年,并且在PHP7中永远消失。如果你只是在学习PHP,那么就把精力花在学习PDO
或mysqli
数据库扩展上。检查$row\u Recordset7['ID']
的内容,然后检查'pics/'$身份证。jpg'代码>实际存在,因此尝试使用绝对路径而不是相对路径。$row_Recordset7['ID'];存在,因为我可以看到所有ID为“存储在pic\文件夹中”的员工姓名,但每次在新代码中使用数据库扩展时,您都会查看“pics/…”,它已被弃用多年,并且在PHP7中永远消失。如果你只是在学习PHP,那么就把精力花在学习PDO
或mysqli
数据库扩展上。我只想显示5个没有个人资料图片的员工姓名。在一张有200名员工和195张照片的表格中,我只需要5个没有照片的员工的名字。有没有办法在MYSQL查询中使用file_exists($image)?我只想显示5个没有个人资料的员工姓名。在一张有200名员工和195张照片的表格中,我只需要5个没有照片的员工的名字。有没有办法在MYSQL查询中使用file_exists($image)?谢谢您的帮助。我现在正在添加一些格式。非常有帮助。我们终于拔掉了所有的牙齿,找到了工作。谢谢你的帮助@RiggsFolly。只有你才能让OP说出真相!不客气@user3258571。祝PDO好运!;)“记住mysql是不安全的,你最好学习PDO或mysqli”——“用预先准备好的语句”。;)谢谢你的帮助。我现在正在添加一些格式。非常有帮助。我们终于拔掉了所有的牙齿,找到了工作。谢谢你的帮助@RiggsFolly。只有你才能让OP说出真相!不客气@user3258571。祝PDO好运!;)“记住mysql是不安全的,你最好学习PDO或mysqli”——“用预先准备好的语句”。;)