gonny Posted December 20, 2008 Share Posted December 20, 2008 Hi all! How I can list categories with entries from two query. example code : $query = $DB->query("SELECT id, title FROM gallery_cat ORDER BY `id` DESC"); $cat = $DB->fetch_row($query); $idcat = $cat['id']; $queryn = $DB->query( "SELECT id, title, image, id_cat FROM gallery WHERE id_cat='$idcat' ORDER BY id DESC"); I want to list like this: CATEGORY 1 image1 - image2 - image3 - image4 - image5 CATEGORY 2 image1 - image2 - image3 - image4 - image5 CATEGORY 3 image1 - image2 - image3 - image4 - image5 ect... by 5 result foreach category. Any help? Link to comment https://forums.phpfreaks.com/topic/137854-listing-mysql-query/ Share on other sites More sharing options...
gonny Posted December 21, 2008 Author Share Posted December 21, 2008 none idea? Link to comment https://forums.phpfreaks.com/topic/137854-listing-mysql-query/#findComment-720681 Share on other sites More sharing options...
trq Posted December 21, 2008 Share Posted December 21, 2008 Id suggest you take a look at this tutorial and get this done in one query. Link to comment https://forums.phpfreaks.com/topic/137854-listing-mysql-query/#findComment-720683 Share on other sites More sharing options...
Mark Baker Posted December 21, 2008 Share Posted December 21, 2008 none idea? To start with, you can join the queries SELECT C.id as cat_id, C.title as cat_title, G.id as gallery_id, G.title as gallery_title, G.image, G.id_cat FROM gallery_cat C, gallery G WHERE G.id_cat = C.id ORDER BY C.id DESC, G.id DESC Link to comment https://forums.phpfreaks.com/topic/137854-listing-mysql-query/#findComment-720684 Share on other sites More sharing options...
gonny Posted December 21, 2008 Author Share Posted December 21, 2008 Your query show : cat1 img1 cat1 img2 cat1 img3 cat2 img1 cat2 img2 ...ect foreach image repeat the category may be should use this?? while( $row = $DB->fetch_row($query) ) { Link to comment https://forums.phpfreaks.com/topic/137854-listing-mysql-query/#findComment-720694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.