bulgin Posted March 5, 2009 Share Posted March 5, 2009 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 More sharing options...
WolfRage Posted March 5, 2009 Share Posted March 5, 2009 Before I try to help you out, I need to know that there is at least something happening in that last else statement and I also need to know that you closed it. At the very least echo something in the last else. Link to comment https://forums.phpfreaks.com/topic/148028-solved-nested-ifs-not-working/#findComment-776995 Share on other sites More sharing options...
bulgin Posted March 5, 2009 Author Share Posted March 5, 2009 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(); } Link to comment https://forums.phpfreaks.com/topic/148028-solved-nested-ifs-not-working/#findComment-776999 Share on other sites More sharing options...
bulgin Posted March 5, 2009 Author Share Posted March 5, 2009 Got it fixed. This was missing: if ($show_page) { where the last else was supposed to be. This might be generic to Joomla only. Thanks for your help, though! Link to comment https://forums.phpfreaks.com/topic/148028-solved-nested-ifs-not-working/#findComment-777005 Share on other sites More sharing options...
WolfRage Posted March 5, 2009 Share Posted March 5, 2009 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. Link to comment https://forums.phpfreaks.com/topic/148028-solved-nested-ifs-not-working/#findComment-777007 Share on other sites More sharing options...
bulgin Posted March 5, 2009 Author Share Posted March 5, 2009 thanks. Link to comment https://forums.phpfreaks.com/topic/148028-solved-nested-ifs-not-working/#findComment-777017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.