HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


How to 'code' this sql?

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#91450 (In Topic #18392)
Avatar

Community saint

Code

SELECT o.name, o.image FROM ocp_ocrewards o WHERE EXISTS (SELECT * FROM ocp_ocrewards_members om WHERE om.reward_id = o.id AND om.user_id=Y AND o.rtype=X)

Obviously it doesn't need the o and om defines, but the tables are sans ocp_ as the system adds that to them…  

Just wondering if there is some function that allows such coding, or if it needs to be hard coded… I'd guess if so there are probably routines that at least change ocrewards into ocp_rewards.

Will look through sources/database.php when I get a chance.

Paul
Back to the top
 
Posted
Rating:
#91462
Avatar

$GLOBALS['SITE_DB']->query('SELECT o.name, o.image FROM '.get_table_prefix().'ocrewards o WHERE EXISTS (SELECT * FROM '.get_table_prefix().'ocrewards_members om WHERE om.reward_id = o.id AND om.user_id=Y AND o.rtype=X)')
which is shorthand for:
$GLOBALS['SITE_DB']->query('SELECT o.name, o.image FROM '.$GLOBALS['SITE_DB']->get_table_prefix().'ocrewards o WHERE EXISTS (SELECT * FROM '.$GLOBALS['SITE_DB']->get_table_prefix().'ocrewards_members om WHERE om.reward_id = o.id AND om.user_id=Y AND o.rtype=X)')


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#91470
Avatar

Community saint

Ah, exactly what I came up with. (the shorthand version).   ;)

Paul
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: