Php-如何检查一行是否存在,并根据结果显示不同的内容?

Php-如何检查一行是否存在,并根据结果显示不同的内容?,php,Php,我有一个吸引人的页面,显示数据库中的一些信息,我在每个页面上都放了一个收藏按钮。这是我的代码: $villageId = $_GET['village']; $sql = "SELECT `AttractionID`, `Name`, `Location`, `Description`, `Airport`, `imglink`,`imglink2`,`imglink3`,`imglink4`,`imglink5` FROM `attractions` WHERE `Attractio

我有一个吸引人的页面,显示数据库中的一些信息,我在每个页面上都放了一个收藏按钮。这是我的代码:

$villageId = $_GET['village']; 
$sql    = "SELECT `AttractionID`, `Name`, `Location`, `Description`, `Airport`, `imglink`,`imglink2`,`imglink3`,`imglink4`,`imglink5`  FROM `attractions` WHERE `AttractionID`='$villageId'";

$result = mysql_query($sql, $link);

if (!$result) {
    echo "DB Error, could not query the database\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}



while ($row = mysql_fetch_assoc($result)) {
    echo "<div class='attractions6'>";
    echo "<div class='attractions5'>";
    echo $row['Name']; 

    echo "<span title='Add to Favorites'>" . "<a href='favourite.php?village=" . $row['AttractionID'] . "'>" . 

 "<img src='img/fav.png'></a>";

    echo  "</span>" ;
    echo "<br />" ;
    echo "<br />";
    echo "</div>";

    echo $row['Description'];
    echo "<br />" ;

    echo "<br />";
    echo " Location: ";

    echo $row['Location'] ." ";
    echo "<br />" ;
    echo "<br />";

    echo " Nearest Airport: ".$row['Airport'] ." ";
    echo "<br />" ;

    echo "<br />";
    echo "</div>";
    echo '<a href="'.$row['imglink'].'" target="_blank"><img src="'.$row['imglink'].' " height="200" width="550"></a>';
    echo "<br />";
    echo '<a href="'.$row['imglink2'].'" target="_blank"><img src="'.$row['imglink2'].' " height="180" width="180"></a>';
    echo "&nbsp";
    echo '<a href="'.$row['imglink3'].'" target="_blank"><img src="'.$row['imglink3'].' " height="180" width="180"></a>';
    echo "&nbsp";
    echo '<a href="'.$row['imglink4'].'" target="_blank"><img src="'.$row['imglink4'].' " height="180" width="180"></a>';
    echo "&nbsp";
    echo '<a href="'.$row['imglink5'].'" target="_blank"><img src="'.$row['imglink5'].' " height="180" width="180"></a>';



    echo "&nbsp;";
    //This is the favorite button. If the user clicks on it the script 
    //will redirect to the favourite.php page where the database will be 
    //checked for duplicates in the attractionID field and will save the favorite. 

    echo "<br />";
    echo "<br />";

}

mysql_free_result($result);
?>
在“吸引”页面上,如果用户已经将此条目保存到收藏夹中,我将显示图片1,如果他们没有,我将显示图片2,我该如何设置


谢谢

我没有看到任何用户id可以帮助您了解哪些用户喜欢什么吸引$sql=SELECT id,AttractionID FROM favorites,其中id='$id'和AttractionID='$villageId'$结果=mysqli_查询$con,$sql;如果$result->num_rows>0{header'location:attraction.php?village='.$villageId;}我将比较的会话ID表示:您正在混合MySQL API,它们不会混合。您在一个代码体中使用mysql,在另一个代码体中使用mysqli。和一个呆在一起,做后者-在数据库中,用户id在哪里?比如你如何选择用户喜欢的东西?
$sql="SELECT `ID`,`AttractionID`  FROM `favourites` 
      WHERE `ID`='$ID' AND `AttractionID`='$villageId'  ";
$result = mysqli_query($con,$sql);

if ($result->num_rows > 0) {
    header('location:attraction.php?village='.$villageId);
}