관련상품이 없을때 안보이게 하려면?
본문
item.form.skin 파일에 아래 소스를 삽입하여 관련상품을 불러오고 있는데요.
관련상품이 없을때는 <h1 id="win_title">관련상품</h1> 부분은 안보이게 하고 싶은데,
어떻게 해야 될지 모르겠어요.
도움 부탁 드려요.
<h1 id="win_title">관련상품</h1>
<?php
$rel_skin_file = $skin_dir.'/'.$default['de_mobile_rel_list_skin'];
if(!is_file($rel_skin_file))
$rel_skin_file = G5_MSHOP_SKIN_PATH.'/'.$default['de_mobile_rel_list_skin'];
$sql = " select b.* from {$g5['g5_shop_item_relation_table']} a left join {$g5['g5_shop_item_table']} b on (a.it_id2=b.it_id) where a.it_id = '{$it['it_id']}' and b.it_use='1' ";
$list = new item_list($rel_skin_file, 1, 1, $default['de_mobile_rel_img_width'], $default['de_mobile_rel_img_height']);
$list->set_mobile(true);
$list->set_query($sql);
$list->set_view('sns', true);
echo $list->run();
?>
답변 1
관련상품이 있는지 먼저 체크후 출력하시면 됩니다.
아래와 같이 해주세요.
<?php
$tmp = sql_fetch(" select count(*) as cnt from {$g5['g5_shop_item_relation_table']} a left
join {$g5['g5_shop_item_table']} b on (a.it_id2=b.it_id) where a.it_id =
'{$it['it_id']}' and b.it_use='1' ");
if ($tmp['cnt'] > 0) {
?>
<h1 id="win_title">관련상품</h1>
<?php
$rel_skin_file = $skin_dir.'/'.$default['de_mobile_rel_list_skin'];
if(!is_file($rel_skin_file))
$rel_skin_file = G5_MSHOP_SKIN_PATH.'/'.$default['de_mobile_rel_list_skin'];
$sql = " select b.* from {$g5['g5_shop_item_relation_table']} a left
join {$g5['g5_shop_item_table']} b on (a.it_id2=b.it_id) where a.it_id =
'{$it['it_id']}' and b.it_use='1' ";
$list = new item_list($rel_skin_file, 1, 1, $default['de_mobile_rel_img_width'], $default['de_mobile_rel_img_height']);
$list->set_mobile(true);
$list->set_query($sql);
$list->set_view('sns', true);
echo $list->run();
?>
<?php } ?>