duanhan9334 2013-05-06 01: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-06 01: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.

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

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输