我有一个PHP
代码,只显示Add to Favourites Button
而非Remove from Favourites
代码。我尝试过使用if(mysqli_num_rows($result) != 0)
它有相同的结果。
<?php
session_start();
$con=mysqli_connect("localhost","UN","PW","DB");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id=$_SESSION['user']['id'];
$code='mosP5EvVopNQ3v22rjgaKfmYB';
$result = mysqli_query("SELECT * FROM favourites WHERE user='$id' AND gamecode='$code'");
$num_rows = mysqli_num_rows($result);
if ($num_rows == 0) {
echo'<img src="/add.gif" height="100" width="100" title="Add to Favourites">';
}
else {
echo'<img src="/remove.gif" height="100" width="100" title="Remove from Favourites">';
}
mysqli_close($con);
?>