Printing a list of 'hidden' records

8 posts by 3 authors in: Forums > CMS Builder
Last Post: December 15, 2008   (RSS)

Re: [gkornbluth] Printing a list of 'hidden' records

By ross - December 11, 2008 - edited: December 11, 2008

Hi Jerry

Thanks for posting!

Your code looks good to me. I did a little test install internally here and used basically the same thing (different field name) and it works for me.

My first though is that perhaps the value for hidden items isn't actually "1". Could you check in the section editor for what values are assigned?

Next, I would setup a test.php file just to try a few things out. Like, maybe just create a quick list that only displays the value of that field like this:

<?php foreach ($artistsRecords as $record ): ?>
<?php echo $record['hidden'] ?><br>
<?php endforeach; ?>

Of course, you'll need that bit of code for the top of the page too. But this page will just display the actual value in "hidden" for each record.

Could you give this all shot and let me know where it gets us?

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/

Re: [gkornbluth] Printing a list of 'hidden' records

By Dave - December 11, 2008

Jerry,

Try adding these options:

'where' => " 0 ",
'orWhere' => " hidden = '1' ",

The "orWhere" adds another condition that if matched will return a record even if it doesn't match any other conditions. Note that this might not work properly with automatic searching, etc.

To see the actual MySQL query that CMS Builder is using add this:
'debugSql' => true,

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Printing a list of 'hidden' records

By gkornbluth - December 12, 2008 - edited: December 12, 2008

Thanks Dave.

Hate to seem dumb. but it's been a really long day.

Where should I insert those lines in my code above?

Or do they appear at the top of the page in the "require once" section?

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

Re: [gkornbluth] Printing a list of 'hidden' records

By Dave - December 14, 2008

In the getRecord() block. You'll see some code like this:

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'perPage' => '8',
));


But you may have different options or values. Add the lines in red:

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'perPage' => '8',
'where' => " 0 ",
'orWhere' => " hidden = '1' ",

));


If that doesn't work post that little block of code from your viewer file and I'll take a look.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Printing a list of 'hidden' records

By gkornbluth - December 14, 2008

Thanks for the direction, Dave,

What actually worked for me was:

list($artistsRecords, $artistsMetaData) = etRecords(array(
'tableName' => 'artists',

'where' => " hidden = '0' ",
'orWhere' => " hidden = '1' ",

));

Then I could use:
<?php if ($record['hidden'] == '1'): ?> or
<?php if ($record['hidden'] == '0'): ?>
to show lists of each category of members on the same viewer page.

Just curious, why is it necessary to use the 'where' statements in the getRecord() block for the "hidden" field and not necessary for any regular fields?

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

Re: [gkornbluth] Printing a list of 'hidden' records

By Dave - December 15, 2008

Glad it's working! :)

>Just curious, why is it necessary to use the 'where'
>statements in the getRecord() block for the "hidden"
>field and not necessary for any regular fields?

The "hidden" field is a special field. Anytime it exists CMS Builder automatically adds "WHERE hidden = 0" to the query. You can see the MySQL query CMS Builder creates by temporarily adding this option below the others:
'debugSql' => true,

You can see a list of other "special" fieldnames here:
http://www.interactivetools.com/docs/cmsbuilder/special_fieldnames.html

Since the purpose and design of the hidden field is to hide those records, when you want to show them instead we need to do some extra work to make it work. :)

Hope that makes sense, let me know if you have any other questions about that.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Printing a list of 'hidden' records

By gkornbluth - December 15, 2008

Ah Ha...

Thanks
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