I've this multiquery
enter code here
SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'MAX(case when b.periode = ''',
date_format(periode, '%Y-%m-%d'),
''' then b.item_terjual end) AS `',
date_format(periode, '%Y-%m-%d'), '`'
) ORDER BY periode SEPARATOR ',
'
) INTO @sql
from penjualan;
SET @sql = CONCAT('SELECT a.kd_barang,', @sql,'
FROM t_barang a
INNER JOIN penjualan b ON a.kd_barang = b.kd_barang
GROUP BY a.kd_barang
ORDER BY a.kd_barang');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
how to excute in PHP , to display table like this
kd_barang | 2014-08-15 | 2014-09-15 | xxx....
123 | 100 | 200
124 | 200 | 300
I try this code but its not dynamic
if (mysqli_multi_query($con,$q))
{
do
{
// Store first result set
if ($result=mysqli_store_result($con))
{
while ($row=mysqli_fetch_array($result))
{
printf("%s
",$row[1]);
echo "<br>";
$count++;
}
mysqli_free_result($con);
}
}
while (mysqli_next_result($con));
}
print_r($data);
mysqli_close($con);
How do I execute multiple queries dynamically in PHP?