studgate Posted June 12, 2009 Share Posted June 12, 2009 I have a table that contains data from two galleries using their id. I want to be able to get a list of each item from a particular gallery and categorize them in groups. The way that I want is: Gallery 1 Item 1 Item 2 Gallery 2 Item 1 Item 2 the code that I have right now gives me: Gallery 1 Item 1 Gallery 1 Item 2 Gallery 2 Item 1 Gallery 2 Item 2 TABLE `table1` ( `id` int(11) NOT NULL auto_increment, `title` varchar(150) NOT NULL, `galleryid` int(11) NOT NULL); Any help is welcome! Link to comment https://forums.phpfreaks.com/topic/161897-categorize-list-help-needed/ Share on other sites More sharing options...
haku Posted June 12, 2009 Share Posted June 12, 2009 http://www.tizag.com/mysqlTutorial/mysqlgroupby.php Link to comment https://forums.phpfreaks.com/topic/161897-categorize-list-help-needed/#findComment-854201 Share on other sites More sharing options...
studgate Posted June 12, 2009 Author Share Posted June 12, 2009 yeah, that won't help, I got the same problem... Link to comment https://forums.phpfreaks.com/topic/161897-categorize-list-help-needed/#findComment-854518 Share on other sites More sharing options...
Ken2k7 Posted June 12, 2009 Share Posted June 12, 2009 Can you post the SQL you used? Just the SQL please. Link to comment https://forums.phpfreaks.com/topic/161897-categorize-list-help-needed/#findComment-854544 Share on other sites More sharing options...
studgate Posted June 12, 2009 Author Share Posted June 12, 2009 $sql = "SELECT `id`, `title`, gallery1' AS type FROM table1 WHERE galleryid = '1' " . " UNION SELECT `id`, `title`, 'gallery2' AS type FROM table1 WHERE galleryid = '2' "; $sql .= "GROUP BY type"; Link to comment https://forums.phpfreaks.com/topic/161897-categorize-list-help-needed/#findComment-854812 Share on other sites More sharing options...
Ken2k7 Posted June 13, 2009 Share Posted June 13, 2009 Take out the GROUP BY clause. Link to comment https://forums.phpfreaks.com/topic/161897-categorize-list-help-needed/#findComment-854865 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.