duanhan9334 2013-05-05 17:17
浏览 30
已采纳

从单个查询中解析多个$变量值?

I'm trying to learn a more economical way of parsing out multiple variable values from a single mysql_fetch_array query. I know I could write a whole series of individual queries to resolve this, but that's a lot of extra coding and queries to hit the server with and that just seems grossly inefficient.

The base query I'd like to work with is:

SELECT vehicletype, vehiclelength
FROM my_dbase.my_table
WHERE arriveday = '08/07/2013' AND process_status = 'completed'

vehicletype has one of four fixed values assigned, and vehiclelength has one of five fixed values assigned from option_value fields on a form page.

What I need is to parse the result of the query to count the number of records found for each pair-combination and assign a $variable value to each pair-combination to display in a PHP-generated table. I have four different dates that I need to run this operation for.

I've tried some iterations of creating an array() or using array_count_values() with the output of the mysql_fetch_array result with no success.

  • 写回答

1条回答 默认 最新

  • duanjue2576 2013-05-05 17:27
    关注

    Perhaps you can try,

    SELECT COUNT(*), vehicletype, vehiclelength 
    FROM my_dbase.my_table WHERE arriveday = '08/07/2013' 
    AND process_status = 'completed' and vehicletype 
    in ('t1','t2','t3','t4') and vehiclelength 
    IN('1','2','3','3') GROUP BY vehicletype, vehiclelength 
    ORDER BY vechicletype
    

    I like to let mysql do all the work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部