0

我在 SQL 数据库中有一个整数,我试图在 php.ini 中找到该整数的值。整数是一张照片的点赞数。这是我的查询:

$result = query("SELECT likes FROM NSPhotos WHERE IdPhoto='%s' LIMIT 1", $imageID);

如何从“$results”中获取整数值?

4

1 回答 1

2

假设您使用 MySQL,您将执行以下操作:

// Establish a connection to the database
$mysqli = new mysql('host', 'user', 'pass', 'database');

$query = "SELECT likes FROM NSPhotos WHERE IdPhoto = ".$imageID." LIMIT 1";
$result= $mysqli -> query($query);
$num   = $mysqli -> num_rows;

if($num > 0){

   // Fetch the result from the database
   $row = $result -> fetch_object();

   // Print the result or you could put it in a variable for use later.
   echo 'Likes: '.$row -> likes;
   $like_count = $row -> likes;

}else{
   echo 'Photo not found.';

}
于 2013-06-01T20:42:00.190 回答