Goodday!我只是想知道这种问题是否存在可能的伎俩。我想在php中获取我的行的图像,我有3个类别的酒店,餐馆和Places To Go,每个类别都有不同的存储空间(文件夹)我已经获取了其他必要的数据但是图像对我来说真的很难做到任何人都可以帮我解决这个问题吗?提前谢谢你:)
//获取数据的Mysql语句
$query = "
SELECT hotel as name, province, address as address, image as image FROM hotel
WHERE CONCAT(hotel,province,address) LIKE '%".$valueToSearch."%'
UNION ALL
SELECT tourist_spot as name, province, address as address, image as image FROM users
WHERE CONCAT(tourist_spot,province,address) LIKE '%".$valueToSearch."%'
UNION ALL
SELECT restau_name as name, province, restau_address as address, image as image FROM restauu
WHERE CONCAT(restau_name,province,restau_address) LIKE '%".$valueToSearch."%'
";
<div class="col-md-4" style="border-left: 3px solid #ff9800;">
<?php while($row = mysqli_fetch_array($search_result)):?>
<div class="ResultContainer">
<div class="SearchResul1" style="float: left;">
<?php
if($valueToSearch = $row['hotel']){
echo "<img src='../hotel/upload/$row[image]' id='TouristImage'>";
}else if($valueToSearch = $row['tourist_spot']){
echo "<img src='../touristspotinformation/upload/$row[image]' id='TouristImage'>";
}else if($valueToSearch = $row['restau_name']){
echo "<img src='../ca/upload/$row[image]' id='TouristImage'>";
}
?>
</div>
<div style="width: 300px; float:left;">
<h3 style="font-size: 20px;"><p><a href="#" style="text-decoration:none; color: #333; font-family: candara;"><?php echo $row['name'];?></a></p></h3>
<span class="fa fa-map-marker"></span><label >Located at <?php echo $row['province']; ?></label><br>
</div>
<div class="SearchResul3" style="float:right;">
<?php echo "<a onclick='window.open(this.href); return false;' href='TourPackages_ViewDetails.php?id=".$row['id']."&packages_name=".$row['package_name']."&packages_image=".$row['image']."&packages_category=".$row['Category']."'><label id='Prices1'><h4>View Details</h4></label></a>"; ?> </div>
</form>
</div>
<div class="clearfix">
<div></div>
<div></div>
</div>
<?php endwhile;?>
&#13;
答案 0 :(得分:2)
if
使用条件==
进行比较时遇到问题=
是赋值运算符
if($valueToSearch == $row['hotel']){
echo "<img src='../hotel/upload/$row[image]' id='TouristImage'>";
}else if($valueToSearch == $row['tourist_spot']){
echo "<img src='../touristspotinformation/upload/$row[image]' id='TouristImage'>";
}else if($valueToSearch == $row['restau_name']){
echo "<img src='../ca/upload/$row[image]' id='TouristImage'>";
}