如果您使用一个条件,我有以下PHP脚本工作(if..else工作正常)如果尝试使用if和else if语句(因为两个条件为真)第二个工作而不是第一个
$damage_topdir = "/ids_images/drsIN2/";
$damage_topdir1 = "/ids_images/drsIN1/";
$tmp = split(" ", $displayEntryDatetime);
$date = $tmp[0];
$time = $tmp[1];
$tmp = split("/", $date);
$day = $tmp[0];
$month = $tmp[1];
$year = $tmp[2];
$displayEntryDatetime = $year."-".$month."-".$day." ".$time;
$cam_list = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
if ($cam = 'DRHdrsIN1')
{
foreach ($cam_list as $cam) {
$timestamp = strtotime($displayEntryDatetime);
$cam_delta =6;
$timestamp = $timestamp - $cam_delta;
for ($i = 0; $i < $cam_delta+20; $i++) {
$cdate = date("d_m_Y* H_i_s", $timestamp);
$image_name = "/xampp/htdocs" . $damage_topdir. $cam . "/Cam*" . $cam . "*-" .$cdate . "*";
foreach (glob($image_name) as $filename) {
if (file_exists($filename)) {
$fs_image = str_replace("/xampp/htdocs", "", $filename);
print "<h3>Camera $cam</h3>";
print "<a href=\"$fs_image\" target=\"_new\"><img src=\"$fs_image\" height=240 width=320 /></a>\n";
}
}
$timestamp++;
}
}
}
elseif($cam = 'DRHdrsIN2') ----> this one executes normally...
{
foreach ($cam_list as $cam) {
$timestamp = strtotime($displayEntryDatetime);
$cam_delta = 6;
$timestamp = $timestamp - $cam_delta;
for ($i = 0; $i < $cam_delta+20; $i++) {
$cdate = date("d_m_Y* H_i_s", $timestamp);
$image_name = "/xampp/htdocs" . $damage_topdir1. $cam . "/Cam*" . $cam . "*-" .$cdate . "*";
foreach (glob($image_name) as $filename) {
if (file_exists($filename)) {
$fs_image = str_replace("/xampp/htdocs", "", $filename);
print "<h3>Camera $cam</h3>";
print "<a href=\"$fs_image\" target=\"_new\"><img src=\"$fs_image\" height=240 width=320 /></a>\n";
}
}
$timestamp++;
}
}
}
else {
}
?>
答案 0 :(得分:0)
您需要使用比较,而不是作业:
if ($cam == 'DRHdrsIN1'){
....
elseif($cam == 'DRHdrsIN2'){
...