Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top