[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
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
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.
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
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
Re: [zip222] Not Show section when there is no records
By gcod - September 9, 2010
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
Re: [zip222] Not Show section when there is no records
By gcod - September 9, 2010
<?php
require_once "/home/jeftay6/vin.com/cmsAdmin/lib/viewer_functions.php";
list($home_pageRecords, $home_pageMetaData) = getRecords(array(
'tableName' => 'home_page',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$home_pageRecord = @$home_pageRecords[0];
list($winesRecords, $winesMetaData) = getRecords(array(
'tableName' => 'wines',
'limit' => '5',
));
list($featured_articlesRecords, $featured_articlesMetaData) = getRecords(array(
'tableName' => 'featured_articles',
'limit' => '5',
));
list($about_usRecords, $about_usMetaData) = getRecords(array(
'tableName' => 'about_us',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$about_usRecord = @$about_usRecords[0];
list($listes_de_produitsRecords, $listes_de_produitsMetaData) = getRecords(array(
'tableName' => 'listes_de_produits',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$listes_de_produitsRecord = @$listes_de_produitsRecords[0];
$page = 'home';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $home_pageRecord['page_title'] ?></title>
<meta name="Description" content="<?php echo $home_pageRecord['meta_description'] ?>" />
<meta name="KeyWords" content="<?php echo $home_pageRecord['meta_keywords'] ?>" />
<link rel="shortcut icon" href="/images/vin.ico">
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen" />
<script src="/js/jquery.v1.4.2.js" type="text/javascript" charset="utf-8"></script>
<!--[if lte IE 6]>
<script src="/js/pngfix/supersleight-min.js" type="text/javascript" charset="utf-8"></script>
<![endif]-->
<!-- Slider -->
<link rel="stylesheet" href="/css/slider.css" type="text/css" media="screen" />
<script src="/js/jquery.easing.1.2.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/jquery.anythingslider.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function formatText(index, panel) {
return index + "";
}
$(function () {
$('.anythingSlider').anythingSlider({
easing: "easeInOutExpo", // Anything other than "linear" or "swing" requires the easing plugin
autoPlay: false, // This turns off the entire FUNCTIONALY, not just if it starts running or not.
delay: 3000, // How long between slide transitions in AutoPlay mode
startStopped: false, // If autoPlay is on, this can force it to start stopped
animationTime: 600, // How long the slide transition takes
hashTags: true, // Should links change the hashtag in the URL?
buildNavigation: true, // If true, builds and list of anchor links to link to each slide
pauseOnHover: true, // If true, and autoPlay is enabled, the show will pause on hover
startText: "Go", // Start text
stopText: "Stop", // Stop text
navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
});
$("#slide-jump").click(function(){
$('.anythingSlider').anythingSlider(6);
});
});
</script>
<!-- Slider end -->
</head>
<body>
<div id="wrap">
<?php include ($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php'); ?>
<div class="anythingSlider">
<div class="wrapper">
<ul class="wineinfo">
<?php foreach ($featured_articlesRecords as $record): ?>
<?php if ($record['active'] == 1): ?>
<li class="containerarticles">
<div class="winepic">
<?php foreach ($record['image'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="433" height="313" alt="<?php echo $record['page_title'] ?>" align="left" />
<?php break; ?>
<?php endforeach ?>
</div>
<div class="article">
<h2><a href="<?php echo $record['_link'] ?>"><?php echo $record['page_title'] ?></a></h2>
<p><?php echo $record['summary'] ?></p>
<a href="<?php echo $record['_link'] ?>"><img width="110" height="28" alt="Learn More" src="/images/more.png"></a>
</div>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
</div>
</div> <!-- END AnythingSlider -->
<div id="homemain">
<h1><?php echo $about_usRecord['title'] ?></h1>
<?php echo $about_usRecord['summary'] ?>
<a href="/apropos.php"><img src="/images/more.png" width="110" height="28" alt="Learn More" /></a>
<h2 id="press">Blog</h2>
<ul id="danslapress">
<?php
include ($_SERVER['DOCUMENT_ROOT'] . '/rss_feeds/rssclass.php');
$feedlist = new rss('http://192.168.1.1/blog/?feed=rss2');
echo $feedlist->display(3,"Blog");
?>
</ul>
</div><!-- homemain end -->
<div id="column">
<?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>
<a href="/nouveaux-arrivages.php" class="narrivages"><img src="/images/view-all-new-arrivals.png" alt="Voir les nouveaux arrivages" width="186" height="28" /></a>
<?php endif; ?>
<div id="follow">
<h2>Suivez-nous...</h2>
<a href="https://twitter.com/vin"><img src="/images/twitter-btn.png" alt="Suivez nous sur Twitter" width="154" height="61" /></a> <a href="http://www.facebook.com/pages/Vins"><img src="/images/facebook-btn.png" alt="Suivez nous sur Facebook" width="154" height="61" /></a>
<h5>Inscription infolettre</h5>
<p>J'aimerais recevoir l'infolettre de Vin!<br />
En tant que client privilégié de Vin, vous serez informé des nouveaux arrivages, des événements spéciaux, dégustations et bien plus encore...<br /></p>
<iframe height="90" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none" src="/machform/embed.php?id=1" title="Inscription Newsletter"></iframe>
<?php include ($_SERVER['DOCUMENT_ROOT'] . '/includes/listeproduits.php'); ?>
</div>
</div><!-- column end -->
<?php include ($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?>
</div> <!-- wrap end -->
</body>
</html>
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com
Re: [gcod] Not Show section when there is no records
By zip222 - September 9, 2010
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
Gab
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com