我正在使用这样的代码
$query = "SELECT Max(Vote) FROM VoteTab";
$result = mysqli_query($this->link,$query);
$query_data = mysqli_fetch_assoc($result);
foreach ($query_data as $record){
$VoteCount=$record['Vote'];
echo $VoteCount;
}
它返回值5,但实际值是56.如果值是67,那么它只返回6.但它在我的localhost中对我来说很好。
Id Vote Name
1 23 Rohan
2 56 Vivek
3 32 Rahul
4 78 Broh
5 0 Tack
6 0 grey
答案 0 :(得分:3)
mysqli_fetch_assoc()
获取结果的一行,然后使用foreach
进行迭代,这是错误的。正确的代码应该是:
$query = "SELECT Max(Vote) FROM VoteTab";
$result = mysqli_query($this->link,$query);
$query_data = mysqli_fetch_assoc($result);
echo $query_data['Max(Vote)'];
答案 1 :(得分:0)
您只需更新查询:
$query = "SELECT Vote FROM VoteTab order by Vote desc limit 1";
$result = mysqli_query($this->link,$query);
$query_data = mysqli_fetch_assoc($result);
foreach ($query_data as $record){
$VoteCount=$record['Vote'];
echo $VoteCount;
}