PHP如果不存在不起作用

时间:2014-06-09 20:20:00

标签: php mysqli

我有一个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);

?>

0 个答案:

没有答案