Jump to content

If/else Depending On Checkbox


Deyan
 Share

Recommended Posts

Hi,

this is probably very easy to solve but I just can get the right output. This is the code:

<?php 
        
        //$tender_open is checkbox field;
        
	$tenders = $pages->find("template=tender, sort=-created, tender_open=$open");
        
        
        
	?>
	<h3>Tenders</h3>
	<?php if($open == 0) {
		echo '<p>There are no tenders available !</p>';
	} else { ?>
	<ul class="no-style">
		<?php foreach ($tenders as $t) { ?>
			<li>
				<a href="<?php echo $t->url; ?>"><?php echo $t->title; ?></a>
				<br>
				<p>Status: <span class="open">Open</span></p>
			</li>
		<?php } ?>
	</ul>
        <?php } ?>

This is the snippet from the homepage. The code should check if there is an open tender available, if true = display it and if false just output echo "There are no tenders available". Tenders are on separate page tree with their own template.

I must be doing something wrong here! Help.

Link to comment
Share on other sites

What value does $open have? I would do it like this:

<?php 
        
$tenders = $pages->find("template=tender, sort=-created, tender_open=1");
    
echo "<h3>Tenders</h3>";

if(count($tenders) == 0)
{
	echo '<p>There are no tenders available!</p>';
} 
else // Otherwise show the output
{
	echo "Output list here";
}
  • Like 5
Link to comment
Share on other sites

Hi,

thanks for your quick reply.

I tried your option too, but it does not work (properly).

If I tick the checkbox (tender_open field), it returns "<p>There are no tenders available!</p>" and if it's not ticked it returns nothing, just a title.

Very strange.

P.S. I was just playing with the $open as I don't know what to do anymore.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...