我需要一些帮助。我有两种类型的图像被保存,但不是必需的。PHP如果陈述
我想默认显示“渲染”图像,但如果没有“渲染”图像,请显示“小册子”图像。
现在,它被设置为显示nopic.png图像,如果没有渲染图像,但我想用小册子图像替换nopic图像。总会有一张小册子图像,所以不需要使用无用图像。
下面是当前的代码...
$query->select('*, c.alias')
->from('#__iproperty_catfp_img i')
->join('inner','#__iproperty_categories c ON c.id = i.cat_id')
->where('i.fp_id = '.(int)$fb_id)
->where('i.cat_id = '.(int)$cat_id)
->where('i.img_type = "rendering"')
->order('i.id DESC');
$db->setQuery($query, 0, 1);
$thumb = $db->loadObject();
$root_path = ($rel_path) ? JURI::root(true) : substr(JURI::root(), 0, -1);
//add appropriate path to thumbnail file
if ($thumb) {// if rendered image
$thumbnail = $root_path."/fpimagegallery/$thumb->alias/$thumb->img_type/$thumb->file_name";
}
else { //no rendered image, show brochure image
$path = $root_path.$settings->fpimgpath;
$thumbnail = $path.'nopic.png';
}
这里是我试过,但没有图像显示...
$query->select('*, c.alias')
->from('#__iproperty_catfp_img i')
->join('inner','#__iproperty_categories c ON c.id = i.cat_id')
->where('i.fp_id = '.(int)$fb_id)
->where('i.cat_id = '.(int)$cat_id)
->where('i.img_type = "rendering" AND "brochure"')
->order('i.id DESC');
$db->setQuery($query, 0, 1);
$thumb = $db->loadObject();
$root_path = ($rel_path) ? JURI::root(true) : substr(JURI::root(), 0, -1);
//add appropriate path to thumbnail file
if ($thumb) {// if rendered image
$thumbnail = $root_path."/fpimagegallery/$thumb->alias/$thumb->rendering/$thumb->file_name";
}
else { //if no rendered image, show brochure image
$thumbnail = $root_path."/fpimagegallery/$thumb->alias/$thumb->brochure/$thumb->file_name";
}
我想如果我字Where语句正确,我可以得到这个工作?
下面是在表... table screenshot http://expressville.com/fp_images_ss.png
而实际上只要文件路径而言...的代码可以甚至改变这样的。所有文件夹都有一个渲染和小册子子文件夹,每个文件夹都有相应的图像。
if ($thumb) {
$thumbnail = $root_path . "/fpimagegallery/{$thumb->alias}/rendering/{$thumb->file_name}";
}
else {
$thumbnail = $root_path . "/fpimagegallery/{$thumb->alias}/brochure/{$thumb->file_name}";
}
它是在浏览器本身指定的图像是“渲染”还是“小册子”? –
渲染和小册子只是图像类型。当图像保存在数据库中时,它会在img_type字段中标记为渲染或小册子。见上面的截图。 – user2837055