0

Sir I want to generate a query which will convert data from rows to columns

I have this table
aa.png

I want to get this result

bb.png

[IMG]http://i66.tinypic.com/2hfjep4.png[/IMG]

Workers amount will go to column in relevant data

Group by code.

I wrote this query

session_start(); 
require_once("includes/connectw.php"); 

$query = "select date,code,worker,sum(amount)as amount from sales group by date,code" ; 
$result = mysqli_query($con,$query)or die ("Error". mysqli_error($con)) ;   
while ($row = mysqli_fetch_array ($result)){ 
    echo($row['date'])."-"; 
    echo($row['code'])."-"; 
    echo($row['worker'])."-"; 
    echo($row['amount'])."<br>"; 
}  

The query show following result

Click Here

But do not know how to display rows data into columns.

Please help

Edited by phphp

Attachments cc.png 5.76 KB
2
Contributors
1
Reply
9
Views
1 Year
Discussion Span
Last Post by rproffitt
0

OK, I read this a few times and can guess the query is in PHP. But to get that table output you have to reveal how you will view the result. It might be this is the backend of a server and the viewer is a browser, but that's not told.

ASCII text would not normally have the needed lines and colors. Maybe a few decades ago you could use ANSI on a terminal but that's very rare.

I think you need to complete the picture. That is, reveal what's viewing this ouput.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.