Do you have questions ? We got the answers!

0
how to get sql table rows as header

Open 1 Answers 24 Views PHP

I need the while results in php with row results kindly help me in getting the results. Thanks in advance.

My SQL Table is like

ID | date      | material | Quantity

01 | 01/01/2018| abc      | 50

02 | 01/01/2018| abc      | 50

03 | 02/01/2018| def      | 50

04 | 03/01/2018| ghi      | 50

sql query:

select sum(Quantity) as 'Total Quantity' group by date

I need the results as:

01/01/2018 | 02/01/2018 | 03/01/2018

100        |50          |50

Kindly help me to get the results in this way

1 Answer

0

You could do like this

$sql = "SELECT sum(Quantity) as Total_Quantity ,date group by date order by date";
$result = $conn->query($sql);

while($row = mysql_fetch_assoc($result))
{
   echo $row['date']." ";
   echo $row['Total_Quantity']." ";
}
by