Jump to content

[SOLVED] nested ifs not working


bulgin

Recommended Posts

Using Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (i486) using readline 5.2

 

I have the following snippet of code which for some reason is not evaluating the last else statement. If the first two conditions are false, the script skips executing what follows the last else.  I am not that good at if...else statements so perhaps another set of eyes can help me.  Here is the code:

 

<?php

$this_user =& JFactory::getUser();
$this_userid = $this_user->get('id');
$this_usertype = $this_user->get('usertype');
$db =& JFactory::getDBO();
if ($this_usertype == 'Author') {
  
    $db->setQuery("SELECT COUNT(*) AS usercount FROM author WHERE au_logged_in_user = '$this_userid'");
    $usercount = $db->loadResult();
    if (intval($usercount) >= 3 ) {
           echo "Sorry Author, you have reached your maximum<br />\n";
    }
}
elseif ($this_usertype == 'Registered') {
  
    $db->setQuery("SELECT COUNT(*) AS usercount FROM customer WHERE logged_in_user = '$this_userid'");
    $usercount = $db->loadResult();
    if (intval($usercount) >= 3  ) {
        echo "Sorry Registered, you have reached your maximum<br />\n";
    }
}

else {

//rest of the code

 

The first two ifs are being evaluated corretly.  I can confirm that through some checks

Link to comment
https://forums.phpfreaks.com/topic/148028-solved-nested-ifs-not-working/
Share on other sites

Thank you Wolf Rage for your quick response.  Following is the code in it's entirety:

 

<?php

$this_user =& JFactory::getUser();
$this_userid = $this_user->get('id');
$this_usertype = $this_user->get('usertype');
$db =& JFactory::getDBO();
if ($this_usertype == 'Author') {
    $db->setQuery("SELECT COUNT(*) AS usercount FROM author WHERE au_logged_in_user = '$this_userid'");
    $usercount = $db->loadResult();
          print $usercount;

}
elseif ($this_usertype == 'Registered') {
    $db->setQuery("SELECT COUNT(*) AS usercount FROM customer WHERE logged_in_user = '$this_userid'");
    $usercount = $db->loadResult();
         print $usercount;

}

else {



$form = $this->form;
echo $form->startTag; ?>
<h1><?php echo $form->label;?></h1>
<?php 
echo $form->intro;
echo $this->plugintop; 
$active = ($form->error != '') ? '' : ' fabrikHide';
echo "<div class='fabrikMainError fabrikError$active'>" . $form->error . "</div>";?>

<div><?php echo $this->message ?></div>
<?php 
if ($this->showEmail) {
	echo $this->emailLink;
}
if ($this->showPDF) {
	echo $this->pdfLink;
}
if ($this->showPrint) {
	echo $this->printLink;
}

foreach ( $this->groups as $group ) {
	?>
	<fieldset class="fabrikGroup" id="group<?php echo $group->id;?>" style="<?php echo $group->css;?>">
	<legend><?php echo $group->title;?></legend>
	<?php if ($group->canRepeat) {
		foreach ($group->subgroups as $subgroup) {
		?>
			<div class="fabrikSubGroup">
				<div class="fabrikSubGroupElements">
					<?php 
					$this->elements = $subgroup;
					echo $this->loadTemplate('group'); 
					?>
				</div>
				<?php if ($group->editable) { ?>
					<div class="fabrikGroupRepeater">
						<a class="addGroup" href="#">
							<img src="components/com_fabrik/views/form/tmpl/default/images/add.png" alt="<?php echo JText::_( 'Add group' );?>" />
						</a> 
						<a class="deleteGroup" href="#">
							<img src="components/com_fabrik/views/form/tmpl/default/images/del.png" alt="<?php echo JText::_( 'Delete group' );?>" />
						</a>
					</div>
				<?php } ?>
			</div>
			<?php
		}
	} else {
		$this->elements = $group->elements;
		echo $this->loadTemplate('group'); 
	}?>
</fieldset>
<?php
}
echo $this->hiddenFields;
?>
<?php echo $this->pluginbottom; ?>
<div class="fabrikActions"><?php echo $form->resetButton;?> <?php echo $form->submitButton;?>
<?php echo $form->copyButton  . " " . $form->gobackButton?>
</div>

<?php 
echo $form->endTag;
echo FabrikHelperHTML::keepalive();

} 

Your else if's look fine. Copy that you got is solved. I was going to tell you to make sure that the variable is being set so I was going to feed it the data. But I have a custom display system that I use for my sites and just like this one nothing happens until $this->Display() is called.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.