Я работаю над двумя SQL, которые похожи, разница только в том, что первый запрос вычисляется между двумя датами и вторым запросом с использованием текущей даты.
PHP:
$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'];}
Пожалуйста, предложите, как получить данные Date, Inward и Outward каждого запроса. Я имею в виду то, что следует записать ниже mysqli_multi_query для получения четырех данных.
Заранее спасибо.
Этот пример из руководства по mysql_multi_query
объясняет, как получить несколько значений, используя multi_query
функция.
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));
}
Других решений пока нет …