Question

The table name is ORDERS.

The table structure and data looks this:

Catno     | Bookno
'============='
1            |    4
1            |    6
1            |    7
2            |    3
2            |    9
3            |    1
3            |    5
3            |    7

Now, I need a report that looks like:

Cat No: 1    2    3
'============='
             4   3   1
             6   9   5
             7        7

How to generate this report using mysql and PHP?

Was it helpful?

Solution

Use this Query

SELECT GROUP_CONCAT(Bookno SEPARATOR ' ') as booknum  FROM ORDERS BY Catno;

Result will be

while ($row = mysql_fetch_assoc($result)) {
      $catno=$row['Catno']
     $arrayResult[$catno]=explode(" ", $row['booknum']);
}

that $arrarResult gives data like you want

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top