检索特定的行数据

时间:2017-01-16 02:33:49

标签: php sql

<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';

1 个答案:

答案 0 :(得分: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'];
  }
}