$search_exploded = explode (" ", $search);
foreach($search_exploded as $search_each){
$x++;
if($x==1)
$construct .="concat_ws(Name, Summary, Description, OpeningHours, Address, Postcode, Keywords) LIKE '%$search_each%' ";
else
$construct .="AND concat_ws(Name, Summary, Description, OpeningHours, Address, Postcode, Keywords) LIKE '%$search_each%' ";
}
$construct ="SELECT * FROM Rating, Attraction WHERE $construct" ;
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "Sorry, there are no matching result for '$search'" ;
else
{
echo "";
while($row = mysql_fetch_assoc($run)){
echo '<a href="details.php?ID=' . $row['AttractionID'] . '"><img class="attractionimg" src="'. $row['ImageUrl'] . '" height="160" width="210" /></a>';
echo '<div class="a-textcontain">';
echo '<h2><a href="details.php?ID=' . $row['AttractionID'] . '">' . $row['Name'] . '</a></h2>';
echo '<p class="a-text">' . $row['Summary'] . '</p>';
echo '</div>';
echo '<img class="rating" src="'. $row['RatingUrl'] . '" height="25" width="140" alt="Rating"/>';
echo '<div class="aborderline"></div>';
break;
}
}
我的数据库中有 12 行数据。当我搜索时,它工作正常,但每个搜索结果重复 12 次。我试过放一个“休息”;就像您在上面看到的那样,但这会将搜索限制为只有一个结果...
有人有想法么?
$construct = "SELECT Attraction.*, Type.TypeName, Rating.RatingUrl";
$construct .= "来自景点";
$construct .= "Inner JOIN Type ON Attraction.Type = Type.TypeID";
$construct .= "Inner JOIN Rating ON Attraction.AttractionID = Rating.AttractionID";
$construct .= "WHERE Attraction = $construct" ;