samcheckdb.php
$sql1="select subtitle,descript from dessert where itemId='oepd1007'";
$result1=mysqli_query($dbhandle,$sql1);
$sql2="select subtitle,descript from dessert where itemId='oepd5148'";
$result2=mysqli_query($dbhandle,$sql2);
<div id="d0"><?php if($result1) { echo $descript1 ;} ?></div>
<div id="s0"><?php if($result1) { echo $subtitle1 ;} ?></div>
<div id="d11"><?php if($result2) {echo $descript2; } ?></div>
<div id="s11"><?php if($result2) { echo $subtitle2 ;} ?></div>
客户
<html>
<li><a href="samcheckdb.php"> <img src="getdesserticecreamimage.php?itemId=oepd1007" alt="image" id="img1" onclick="get_detail('oepd1007');"></a></li>
<li> <a href="samcheckdb.php"><img src="getdesserticecreamimage.php?itemId=oepd5148" alt="image" id="img2"></a></li>
</html>
我需要在页面中一次只显示1个字幕和描述,当用户点击图像时,只显示特定图像的相应信息,而不显示其余信息。
答案 0 :(得分:3)
另一种更简洁的方法是使用:block
<?php if ($result1): ?>
<div id="d0"><?php echo $descript1 ; ?></div>
<div id="s0"><?php echo $subtitle1 ; ?></div>
<?php elseif($result2): ?>
<div id="d11"><?php echo $descript2 ; ?></div>
<div id="s11"><?php echo $subtitle2 ; ?></div>
<?php endif; ?>
答案 1 :(得分:1)
<?php if($result1) { ?>
<div id="0"><?php echo $descript1; ?></div>
<div id="s0"><?php echo $subtitle1; ?></div>
<?php } else { ?>
<div id="d11"><?php echo $descript2; ?></div>
<div id="s11"><?php echo $subtitle2; ?></div>
<?php } ?>
答案 2 :(得分:0)
永远记住,您可以回显PHP中的所有HTML元素。
<?php
if($result1) {
echo '<div id="d0">' . $descript1 .'</div>';
echo '<div id="s0">' . $subtitle1 .' </div>';
}
if($result2) {
echo '<div id="d11">' . $descript2 .'</div>';
echo '<div id="s11">' . $subtitle2 .'</div>';
}
?>
答案 3 :(得分:0)
试
echo (isset($result1) ? '<div id="d0">'. $descript1 .'</div><div id="s0">'.$subtitle1 .'</div>': '<div id="d11">'.$descript2 .'</div><div id="s11">'.$subtitle2 .'</div>');