首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP:如何使用mysql_multi_query()执行多重查询

问PHP:如何使用mysql_multi_query()执行多重查询
EN

Stack Overflow用户
提问于 2016-06-08 02:02:45
回答 1查看 158关注 0票数 0

我在两个SQL上工作,这是相似的,只是在第一个查询的差异是在两个日期之间的库存计算和第二个查询使用当前日期。

PHP:

代码语言:javascript
复制
   $sql="select all_dates.value1 as `Date`, sum(coalesce(`Inward(B_Qty)`, '0')) as `Inward`, sum(coalesce(`Outward(B_Qty)`, '0')) as `Outward` 
    from ( select distinct M_Date as value1 from machine where J_Name = '180MLGMV' and DATE(M_Date) between '2016-06-01' and '2016-06-06' 
    union select distinct M_Date from machine where Pre_Req = '180MLGMV' and DATE(M_Date) between '2016-06-01' and '2016-06-06' ) as all_dates 
    left join (select M_Date, sum(A_Prod) AS `Inward(B_Qty)` 
    from machine where J_Name = '180MLGMV' and DATE(M_Date) between '2016-06-01' and '2016-06-06' group by M_Date) 
    as g on g.M_Date = all_dates.value1 
    left join( select M_Date, sum(NoBot) AS `Outward(B_Qty)` 
    from machine where Pre_req ='180MLGMV' and DATE(M_Date) between '2016-06-01' and '2016-06-06' group by M_Date) 
    as f on f.M_Date = all_dates.value1 group by all_dates.value1 ;" ;

    $sql.="select all_dates.value1 as `Date`, sum(coalesce(`Inward(B_Qty)`, '0')) as `Inward`, sum(coalesce(`Outward(B_Qty)`, '0')) as `Outward` 
    from ( select distinct M_Date as value1 from machine where J_Name = '180MLGMV' and M_Date='2016-06-07'
    union select distinct M_Date from machine where Pre_Req = '180MLGMV' and M_Date='2016-06-07' ) as all_dates 
    left join (select M_Date, sum(A_Prod) AS `Inward(B_Qty)` 
    from machine where J_Name = '180MLGMV' and M_Date='2016-06-07' group by M_Date) 
    as g on g.M_Date = all_dates.value1 
    left join( select M_Date, sum(NoBot) AS `Outward(B_Qty)` 
    from machine where Pre_req ='180MLGMV' and M_Date='2016-06-07' group by M_Date) 
    as f on f.M_Date = all_dates.value1 group by all_dates.value1 "; 

    $list1=mysqli_multi_query($sql,$con);
    while($row_list1=mysql_fetch_array($list1))
               { 
                 $b=$b+$row_list1['Inward'];
                $c=$c+$row_list1['Outward'];


}

请建议如何检索每个查询的日期、向内和向外的数据。我的意思是在mysqli_multi_query下面应该写什么来检索这四个数据。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-06-08 02:08:59

mysql_multi_query手册中的这个示例解释了如何使用multi_query函数获取多个值。

代码语言:javascript
复制
if (mysqli_multi_query($link, $query)) {
    do {
        /* store first result set */
        if ($result = mysqli_store_result($link)) {
            while ($row = mysqli_fetch_row($result)) {
                printf("%s\n", $row[0]);
            }
            mysqli_free_result($result);
        }
        /* print divider */
        if (mysqli_more_results($link)) {
            printf("-----------------\n");
        }
    } while (mysqli_next_result($link));
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37686281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档