2016-07-21 43 views
1

請我怎麼知道的次數大衛的2我怎麼知道一個值出現在mysqli的選擇的次數

投票
Name | Vote 
------------- 
|Gabri| 2 
|David| 2 
|Janny| 3 
|David| 1 
|David| 2 
|Fally| 3 
+1

'select count(*)fr om thetable where Name =「David」and Vote = 2' – splash58

+0

http://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html –

+0

好的,謝謝你的回覆,但我該如何返回如果找到了投票的價值 –

回答

0
$sql = "SELECT count(*) from table_name WHERE Name= 'David' and Vote=2"; 
$result = mysqli_query($con, $sql); 
$fetch = mysqli_fetch_assoc($result); 
echo "<pre>"; 
print_r($fetch); 
echo "<pre>"; 

輸出

Array 
(
    [count(*)] => 4 
) 

以獲得您需要的值echo $fetch['count(*)']; //outputs 4

0
select Name , count(Name) where Name = 'David' group by Name having count(Name) =2 
相關問題