2013-12-10 113 views
0

我想使用多個查詢來計算多個值並在一個表中顯示這些值。計數多個值查詢

$resultnieuws = mysql_query("select gamer_int, count(gamer_int) as gamer_count_nieuws  FROM berichten WHERE gamer_int LIKE 'Kenny' AND soort LIKE 'nieuws'"); 
$resultvideo = mysql_query("select gamer_int, count(gamer_int) as gamer_count_video FROM berichten WHERE gamer_int LIKE 'Kenny' AND soort LIKE 'video'"); 

echo $resultnieuws['gamer_count_nieuws']; 
echo $resultvideo['gamer_count_video']; 

上面的回聲給我沒有結果。我究竟做錯了什麼?

回答

1

嘗試像這個 -

$resultnieuws = mysql_query("select gamer_int, count(gamer_int) as gamer_count_nieuws  FROM berichten WHERE gamer_int LIKE 'Kenny' AND soort LIKE 'nieuws'"); 
    $resultvideo = mysql_query("select gamer_int, count(gamer_int) as gamer_count_video FROM berichten WHERE gamer_int LIKE 'Kenny' AND soort LIKE 'video'"); 

    $row1 = mysql_fetch_array($resultnieuws); 
    $row2 = mysql_fetch_array($resultvideo); 

    echo $row1['gamer_count_nieuws']; 
    echo $row2['gamer_count_video']; 

注:mysql_ *功能已被棄用,用起來不推薦。

+0

使用他們甚至**不鼓勵**。 –

+0

這不行;由於某種原因,我的編輯被拒絕了,但是您不能從'$ row1 ['gamer_count_nieuws']'中引用該字段,您需要從結果的第一行中選擇它。例如。 '$ row1 [0] ['gamer_count_nieuws']' – Ryan

+0

完美運作!謝謝! – user2959441