Limit number of records returned when certain criteria are met using mySQL

6 posts by 3 authors in: Forums > CMS Builder
Last Post: January 10, 2014   (RSS)

By Daryl - January 3, 2014

Hi Jerry,

What I would do is that I will create only one mysql query for all membership levels then check if the logged in user is a membership_level 2. If yes, get the first record only and display it. For example: 

if ($userMembershipLevel == "2"){
// get the first record only
$listingsRecords = @$listingRecords[0];
}

Hope this helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By gkornbluth - January 3, 2014 - edited: January 3, 2014

Hi Daryl,

Sorry if I confused the issue, whether the user is logged in or not has nothing to do with my request.

It's not the logged in user that I'm going for, it's anyone who visits the site.

Scenario 1) Visitors should only be able to see the first membership_level == 2 record with status == Available, as well as all records for all other users with status == Available

Scenario 2) Visitors should only be able to see the first membership_level == 2 record regardless of status, as well as all records for all other users regardless of status

Thanks,

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By ross - January 7, 2014

Hi Jerry

I've had an idea for you that doesn't involve SQL.  My idea would be to write a script that hides all but the most recent "available" record created by accounts set to type 2.  That way, you don't need any extra SQL on the page when you load records.

Does that make sense? Let me know what you think.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By gkornbluth - January 7, 2014

Sorry, Ross

I was out for a bit (dinner)

That certainly sounds interesting.

would that mean no extra server load or delays in page load?

If so it sounds like an interesting plan

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By ross - January 10, 2014

Hi Jerry

You and I have already spoken about this but wanted to update the thread for anyone else following along.

Basically, what we ended up doing here is creating a plugin that hides all of a free user's records except for the one that was just created or just saved. Pretty simple plugin :).

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/