Jump to content

Listing mysql query


gonny

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.