Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post

    Trouble with if/else

    I'm trying to build a simple pagination and the only thing that seems to work is the else statement, none of the if statements seem to work.

    Here's what I have:
    Code:
    <?php 	if (journalsclass) 
    			$db =& JFactory::getDBO();
    			$article =& JTable::getInstance('content');
    			$article->load(JRequest::getInt('id'));
    			$articleid = $article->id;
    			$author = $article->created_by;
    $query = "SELECT id FROM #__content WHERE created_by = $author AND id < $articleid ORDER BY id desc LIMIT 1";
    $db->setQuery( $query );
    $previous = $db->loadResult();
    
    $query = "SELECT id FROM #__content WHERE created_by = $author AND id > $articleid ORDER BY id asc LIMIT 1";
    $db->setQuery( $query );
    $next = $db->loadResult();
    
    if ($previous < 1) {
    $pagenav = "<span style='float:left; margin:0px 0px 0px 10px;'><a href='index.php?option=com_content&view=article&id=$previous&catid=16&Itemid=221&tmpl=component'>Next</a></span>"; }
    
    if ($next < 1) {
    $pagenav = "<span style='float:left; margin:0px 0px 0px 10px;'><a href='index.php?option=com_content&view=article&id=$previous&catid=16&Itemid=221&tmpl=component'>Previous</a></span>"; }
    
    if ($next < 1 AND $previous < 1) {
    $pagenav = "<span style='float:left; margin:0px 0px 0px 10px;'></span>"; }
    
    else {
    $pagenav = "<span style='float:left; margin:0px 0px 0px 10px;'><a href='index.php?option=com_content&view=article&id=$previous&catid=16&Itemid=221&tmpl=component'>Previous</a></span><span style='float:right; margin:0px 30px 0px 0px;'><a href='index.php?option=com_content&view=article&id=$next&catid=16&Itemid=221&tmpl=component'>Next</a></span>"; } 
    
    echo "<div class='journalnav' style='background:url(/images/journalbottom.png); height: 36px; width:473px;'>$pagenav</div>";
    ?>
    I've tried several variation of isset(), empty(), and = null and nothing seems to work. I've also tried if elseif elseif else and that didn't work either, What am I doing wrong here?
    Last edited by sfraise; 01-31-2011 at 10:28 AM.

  • #2
    Regular Coder Stooshie's Avatar
    Join Date
    Mar 2008
    Location
    Dundee, Scotland
    Posts
    378
    Thanks
    9
    Thanked 39 Times in 39 Posts
    shouldn't the if statement be
    Code:
    if ($journalsclass)
    I think if you miss out the $, the if statement will return false, rather than an error.
    Regards, Stooshie
    O

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post
    I figured it out, I need to use if on all but the last one where I needed to use an else if.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •