TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-29-2009, 03:11 PM   #1 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default Advanced Query

I currently have a system which employs cascading user levels there is first the Group User levels and their associated rules than there are the User Specific "rules" with the ladder over riding the former.

Currently I'm employing 2 queries to check for the User and exit out or the Group, how ever I was wondering if it could be done in one.

Currently employed queries

sql Code:
SELECT DISTINCT ea_acl_options.`handler`,
         ea_acl_options.`page`,
         ea_acl_options.`limit`
         ea_acl_options.isgroup,
         ea_acl_options.`allowed`
         ea_acl_options.`guid` AS gid, 
         ea_user_levels.sort
FROM ea_acl_options
JOIN ea_user_belongs
LEFT JOIN ea_user_levels ON ea_user_levels.id = ea_user_belongs.g_id
WHERE guid=2 OR guid=0 AND isgroup=0

sql Code:
SELECT DISTINCT ea_acl_options.`handler`,
          ea_acl_options.`page`,
          ea_acl_options.`limit`,
          ea_acl_options.`isgroup`,
          ea_acl_options.`allowed`,
          ea_acl_options.`guid` AS gid, 
          ea_user_levels.sort
FROM ea_acl_options
JOIN ea_user_belongs ON ea_acl_options.guid = ea_user_belongs.g_id
JOIN ea_user_levels ON ea_user_belongs.g_id = ea_user_levels.id 
WHERE ea_user_belongs.u_id = 2 AND ea_acl_options.isgroup = 1

It differs by the last three lines. I might need to rethink my database design...

Perchance could anyone tell me what I could do? I was thinking of using the UNION statement but then there are possibilities of a group and a user having the same id.
__________________
My Blog

Last edited by Enfernikus : 06-29-2009 at 03:41 PM.
Enfernikus is offline  
Reply With Quote
Old 06-30-2009, 02:18 PM   #2 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

I think you need to change the design of your database. Take a step back and ask yourself.

What tables can I merge and what tables can I get rid of?

If you database is no longer 100% 3nf who cares. You should not have to do 2 joins in a single query. You really want to avoid as many joins as possible as they will slow down your querys a greay deal once the database gets some size to it.
CoryMathews is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Full Text Searches with Query Expansion Orc MySQL & Databases 4 12-19-2008 08:39 PM
Query With a C# Variable?‏ StevenF The Lounge 5 12-08-2008 05:32 AM
Create your own advanced WYSIWYG editor almsamim Javascript, AJAX, E4X 8 10-23-2008 06:41 PM
query question Evulness Absolute Beginners 4 04-21-2008 07:46 PM
Query caching xenon Advanced PHP Programming 4 01-29-2008 08:20 PM


All times are GMT. The time now is 12:11 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design