2015-08-27 44 views
0

這是我遇到的問題。單獨計數並提取每個數字並計算每個數字在數據庫中出現的次數

我的表有作爲列MSISDN,我想指望單獨提取每個號碼並計算每個號碼出現的次數 然後在表中顯示它的具體數量和它發生的次數,如

 
Number(MSISDN) | No of times 

這是我的代碼,我有庫存,因爲我不知道要採取什麼步驟或如何從我的位置移動。

$go=mysql_query("SELECT * FROM request_from"); 
$go2=mysql_fetch_array($go); 

$i=0; 
while($go2=mysql_fetch_array($go)) 
{ 
$i++; 

$tel=$go2['msisdn']; 

//counting number of time each number occurs 
$xtt=mysql_query("SELECT * FROM request_from WHERE msisdn='$tel'"); 

$xtt2=mysql_fetch_array($xtt); 

$g=1; 
while($xtt2=mysql_fetch_array($xtt)) 
{ 
    $g++; 
} 
echo $tel occurs $g times; //for all the phone numbers, it displays the number of time each number occurs 
+0

請發表完整的代碼.. – learner

+0

是計取一個動詞? – Strawberry

回答

0

做到這一點:

SELECT msisdn ,sum(1) anz FROM request_from 
GROUP BY msisdn; 
0

它的簡單得多做這在SQL:

SELECT msisdn, COUNT(*) AS number_of_occurrances FROM request_from GROUP BY msisdn; 
相關問題