poe Posted October 27, 2007 Share Posted October 27, 2007 i have a db table that has linkid cat id and page number linkid catid page 1 1 1 2 1 1 3 1 1 4 1 2 5 1 2 6 1 2 7 1 3 8 2 1 9 2 1 10 2 1 11 3 1 12 3 1 13 3 2 14 3 2 15 3 3 16 3 3 17 3 4 18 3 4 etc..... i need to create this into an array that is in a structure like: array [catid] => grouped by catid and just the unique pages so cat1 has pages 1,2,3 cat2 has pages 1 cat3 has pages 1,2,3,4 Link to comment https://forums.phpfreaks.com/topic/74964-db-to-array/ Share on other sites More sharing options...
Barand Posted October 27, 2007 Share Posted October 27, 2007 $catpages = array(); $result = mysql_query("SELECT DISTINCT catid, page FROM tablename"); while ($r = mysql_fetch_assoc($result)) { $catpages[ $r['catid'] ][] = $r['page']; } Link to comment https://forums.phpfreaks.com/topic/74964-db-to-array/#findComment-379152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.