Showing articles only for members with a specific member level

5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 20, 2013   (RSS)

Hi All,

It’s been a long day and my brain is getting fried. I have a feeling this is simple to do, but I’m having a bit of trouble getting my head around it. I hope someone is willing to come to my rescue.

In a site that I’ve inherited, there’s a multi-record section (called articles). Each record contains one article written by a member author.

Each member author can have a membership level of either free, intermediate, or master. Currently, this membership level value is stored in a text field in the accounts database, together with some other text, however I have set up a separate field for future writer’s accounts. ( so I guess I’ll need to use an OR and possibly strpos on the list viewer to accommodate both the old system and the new one.)

What I'm after is that on a “featured writer’s” list page, I need to show only those articles written by members with “master” level membership.

Here’s kind of a schematic of what I’m thinking:

<?php foreach ($articlesRecords as $record): ?>
1) check the accounts database for the membership level of the matching createdByUserNum record.
2) If the author’s membership level is “master”, show some information from that articles record.
<?php endforeach ?>

Thanks in advance,

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 Dave - November 19, 2013

Hi Jerry, 

What's an estimate of the number of articles and authors you expect?

One way to do it is to do a query to get all the usernums who have a "master" level membership, then another query to load all articles that have been created by a user in that list of user nums.

Let me know, thanks!

Dave Edis - Senior Developer
interactivetools.com

By Dave - November 20, 2013

Hi Jerry, 

Maybe you could do a sub-query as a where.

So say you want to get a list of all the user numbers that have "a" in their username, here's a query for that:

SELECT num FROM cms_accounts WHERE username LIKE "%a%"

And then you want a list of all the articles:

SELECT * FROM cms_articles

Or a list of all the articles from created by users who have an "a" in their username:

SELECT * FROM cms_articles WHERE createdByUserNum IN (SELECT num FROM cms_accounts WHERE username LIKE "%a%")

Or as a getRecords option:

'where' => " createdByUserNum IN (SELECT num FROM cms_accounts WHERE username LIKE '%a%')", 

Would something like that work for you? 

Dave Edis - Senior Developer
interactivetools.com

By gkornbluth - November 20, 2013 - edited: November 20, 2013

Hi Dave,

That's just what I needed.

I used the last suggestion in the load records call, like this: (adding the requirement of the "status" field having the value "available")

 <?php // load records from 'lm_listing'
  list($lm_listingRecords, $lm_listingMetaData) = getRecords(array(
    'tableName'   => 'lm_listing',
    'loadUploads' => true,
     'where' => " createdByUserNum IN (SELECT num FROM cms_accounts WHERE internal_notes LIKE '%12.%') AND status = 'Available' ", ",
    'perPage' => $maximages,
  ));
 ?>

And it seems to work perfectly.

Thanks again,

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