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.

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

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了