php - Echo employee name if file does not exist -
i using following code try display records of employees without profile picture. profile pics stored in pics/ folder labeled id_number.jpg (e.g. 4567.jpg). if no pic found, want echo employee's name.
$id = $row_recordset7['id']; $image = 'pics/' . $id . '.jpg'; if (!file_exists($image)) { echo $row_recordset7['employee_name']; } currently, employee names being echoed. appreciated.
mysql_select_db($database_schedule, $schedule); $query_recordset7 = "select distinct id, employee_name, department unit order 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); complete code:
mysql_select_db($database_schedule, $schedule); $query_recordset7 = "select distinct schedule.id, schedule.employee_name, schedule.department schedule order 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 { ?> <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>
since informations gave me , riggsfolly, you'll have loop through sql result data want apply condition :
mysql_select_db($database_schedule, $schedule); $query_recordset7 = "select distinct id, employee_name, department unit order 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']; } } hope helps.
ps : remember mysql_ insecure , you'd better learn pdo or mysqli_ prepared statement.
Comments
Post a Comment