Sorry for the complex title.
I have this schema:
Categories Albums Photos ---------- ------- ------- - ID id ID category_ID album_id From these tables I need to create a navigation menu like this:
category 1 album 1 album 2 category 2 albums 3 Category 3 Album 4 I can make it easily, but now I would like to show only those albums which include at least one photo and only those categories Must have at least one album included. How can I do this?
Edit: I am using Codeigniter and now I am doing it like this:
In an administrator, I create an array using two simple questions. I
$ categories = $ this- & gt; Category-> Get_categories (); Foreign Currency (categories as category $) {$ data ['categories'] [$ class-> Name] = $ this- & gt; Album-> Get_albums_by_category ($ category-> ID); } get_categories () query:
function get_categories () {$ this- & gt; Db- & gt; Select ('*') - & gt; ('Categories'); Refund $ -> -> (-) - & gt; result (); } and get_albums one:
function get_albums_by_category ($ category_id) {// per stampare il null dell'lam num langua zetaata $ lang = $ this - & gt; Lang- & gt; Lang (); $ Name = $ lang 'name_'; $ '-' ('AS', 'AS' as the name '$ id.') - & gt; From ('album') - & gt; Group_b ('id') - & gt; Where ('category_id', $ category_id); Refund $ -> -> (-) - & gt; result (); } I used two questions so that I got the array according to its requirement.
Let's start with your base query:
select (case When type = 'Category' ends the other album in the category) (as 'Category' type, category, tap in the form of album) category all (Select category, 'album', category, album From a category joining the album on c.cid_id = c.id). Order, Category Now, we can modify it for your question: < Pre> choose (case When type = 'category' then ends the other album of the category) (As you type in the category of 'Category', the category, as the album from the tap categories, where in the CID (from the album) Category_id)) Select Union (All Select 'album', album, one category categories in album from album c. Categor_id = c.id where a.id (Choose album_id from photo)) T series, album < / Code>
Comments
Post a Comment