2017-01-16 66 views
0
<code> 
select t.range as [Type], count(*) as [Value] 
from (select case 
     when answer_count between 0 and 5 then 'PCS' 
     when answer_count between 5 and 10 then 'PRINTER' 
     else 'KEYBOARD' end as range 
     from points where type='product_quiz') t 
group by t.range 
</code> 
 
Output is: 
--------------------- 
Type  |  Value 
--------------------- 
PCS   129195 
PRINTER  121327 
OTHERS   236548 


I want to echo only for the printer value using PHP. 
For example I want the result like this: 

    echo $printer = '121327'; 
+2

應該在'SQL'簡單'Where'條款。 '..)t其中t.range ='PRINTER'組由t.range' –

+0

嗨,我不想用sql來實現這一點,我需要在PHP中得到結果。 – Poornima

回答

0

試試這個:

$query = mysql_query("select t.range as [Type], count(*) as [Value] 
from (select case 
    when answer_count between 0 and 5 then 'PCS' 
    when answer_count between 5 and 10 then 'PRINTER' 
    else 'KEYBOARD' end as range 
    from points where type='product_quiz') t 
    group by t.range"); 
while($row = mysql_fetch_assoc($query)) 
{ 
    if($row['type'] == 'PRINTER'){ 
    echo $printer = $row['value']; 
    } 
} 
+0

感謝Adhan Timothy Younes.This是我的預期。 – Poornima