Jump to content

Seeking help with getting resultset from multiple tables


Recommended Posts

I\'m trying to make a \'most recent entries\' list for my intranet site.

 

I want his list to show the last 10 entries from 3 or more tables.

 

I only want it to show entries the user has access to (I use a very simple function to check the users access level in the category for each entry).

 

 

I can\'t figure out how to make a mysql query that returns certain fields from the 3 or more tables, and sorts them after the \'date published\'-field in each table, and filters out expired items based on the \'expire date\'-field (the names of these fields are not the same in all the tables).

 

If I can get this far, I\'m going to try and make a loop in php that checks the users access against each entry in the result untill 10 are found.

 

 

Can anyone help?

  • 2 weeks later...

I would recommend storing some sort of access level in your tables and letting mySQL filter the results based on that.

 

 

select t1.*,t2.*, t3.*

from table1 t1,

inner join table2 t2 on t1.id=t2.id

inner join table3 t3 on t2.id=t3.id

where t1.user_level<=$user_level

and t2.user_level<=$user_level

and t2.user_level<=$user_level

order by t1.date_published

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.