[Solved] Not Show section when there is no records

9 posts by 3 authors in: Forums > CMS Builder
Last Post: September 9, 2010   (RSS)

By gcod - September 5, 2010 - edited: September 9, 2010

Hi,

I have a section on a page and I want it to not show if there is no records in the winesRecords table (I mean the all shabang: the h2, open ul and the close ul):

<h2>Les nouveaux arrivages</h2>
<ul class="narrivage">
<?php foreach ($winesRecords as $record): ?>
<?php if ($record['nouveaux_arrivages'] == 1): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['page_title'] ?></a></li>
<?php endif ?>
<?php endforeach ?>

</ul>


Any ideas?

Thanks!
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

Re: [gcod] Not Show section when there is no records

By Damon - September 6, 2010

Hi,

To have all the content, including the h2, open ul and the close ul, not appear if there is no records, wrap the code in an IF statement.

The content will only display if there is a record in the winesRecords table

<?php if($winesRecords) : ?>

<h2>Les nouveaux arrivages</h2>
<ul class="narrivage">
<?php foreach ($winesRecords as $record): ?>
<?php if ($record['nouveaux_arrivages'] == 1): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['page_title'] ?></a></li>
<?php endif ?>
<?php endforeach ?>

</ul>

<?php endif; ?>


Give that a try.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Not Show section when there is no records

By gcod - September 8, 2010

Doesn't work :(

Should I change something at the top?

list($winesRecords, $winesMetaData) = getRecords(array(
'tableName' => 'wines',
'limit' => '5',
));

---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

Re: [gcod] Not Show section when there is no records

By zip222 - September 9, 2010

That really should work. It could be a typo somewhere in the code. Can you post your page code?

Re: [zip222] Not Show section when there is no records

By gcod - September 9, 2010

My bad, let me reformulate.

There are records in the winetable, but I only show the ones that has a value "1" in the for the column "nouveaux arrivages".

If there are no wines with the value "1" in the "nouveaux arrivages" column I'd like to not show the section.

Let me know if it's clearer.

Thanks.
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

Re: [gcod] Not Show section when there is no records

By zip222 - September 9, 2010

Your approach is fine and the page should work as intended. What is it that's not working?

Re: [gcod] Not Show section when there is no records

By zip222 - September 9, 2010

I think I know how to solve your problem. You need to do two things. in the list function at the top of your page, add the following:
list($winesRecords, $winesMetaData) = getRecords(array(
'tableName' => 'wines',
'limit' => '5',
'where' => 'nouveaux_arrivages=1',
));


And then in the html area, you should remove this completely:
<?php if ($record['nouveaux_arrivages'] == 1): ?>

Re: [zip222] Not Show section when there is no records

By gcod - September 9, 2010

It's working, thanks for you help.

Gab
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com