Jump to content

MySQL 4.0.16 query should be easy, but it isn't :-(


PBeakley

Recommended Posts

I'm building a website for a school. A major part of this is granting editing rights to certain users (administrators, teachers, volunteers, etc.) for certain pages. I'm doing this with a simple join table (id_page, id_user, id_pageeditorlookup as the primary).

 

In addition, each page as a news feed. Any news entry can be assigned to multiple pages: i.e. the results of a football game can appear on the team's page, the site's front page, and on the students' page. I'm doing this with another join table (id_news, id_page, id_newslookup as the primary).

 

This is where it gets tricky.

 

I want to restrict the "assign this news to page X" funtion to the range of pages a particular user is allowed to edit. Right now, the only version of this form that I've gotten to work brings ALL the pages in the site up on the form, with the pages to which this news item is assigned being checked off. Fine for a "superadmin" who has full rights everywhere, but I want to limit this list to just the pages for which this particular user has editing rights.

 

This is the working query that brings up all available pages:

 

SELECT pagecontent.ID_pagecontent, pagecontent.description_pagecontent, newslookup.ID_news
FROM pagecontent LEFT JOIN newslookup ON (newslookup.ID_page=pagecontent.ID_pagecontent AND newslookup.ID_news=0123456789)
ORDER BY pagecontent.description_pagecontent ASC

 

This is the query I THOUGHT would do what I want it to do:

 

SELECT pagecontent.ID_pagecontent, pagecontent.description_pagecontent,
news.ID_news
FROM (pageeditorlookup LEFT JOIN pagecontent on pageeditorlookup.ID_page
= pagecontent.ID_pagecontent) Left Join (SELECT newslookup.ID_page,
newslookup.ID_news FROM newslookup WHERE newslookup.ID_news = 0123456789) AS
news on pagecontent.ID_pagecontent = news.ID_page
WHERE 
ID_useraccount = $_GET['ID']

 

As should this

 

 

SELECT pagecontent.ID_pagecontent, pagecontent.description_pagecontent,
news.ID_news
FROM 
((SELECT newslookup.ID_page, newslookup.ID_news FROM newslookup WHERE
newslookup.ID_news = 0123456789) AS news right join pagecontent on news.ID_page
= pagecontent.ID_pagecontent)  RIGHT JOIN pageeditorlookup  on
pagecontent.ID_pagecontent = pageeditorlookup.ID_page 
WHERE 
ID_useraccount = $_GET['ID']

 

So I'm wondering...how do I return a result where the available pages you can assign this news item to can ONLY correlate to pages the logged-in editor can edit?

 

Thanks for listening!

 

p.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.