Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2011, 09:40 AM   PM User | #1
sfraise
Regular Coder

 
Join Date: Mar 2009
Posts: 175
Thanks: 3
Thanked 1 Time in 1 Post
sfraise is an unknown quantity at this point
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..
sfraise is offline   Reply With Quote
Old 01-31-2011, 11:39 AM   PM User | #2
Stooshie
Regular Coder

 
Stooshie's Avatar
 
Join Date: Mar 2008
Location: Dundee, Scotland
Posts: 376
Thanks: 9
Thanked 39 Times in 39 Posts
Stooshie is on a distinguished road
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
Stooshie is offline   Reply With Quote
Old 01-31-2011, 09:34 PM   PM User | #3
sfraise
Regular Coder

 
Join Date: Mar 2009
Posts: 175
Thanks: 3
Thanked 1 Time in 1 Post
sfraise is an unknown quantity at this point
I figured it out, I need to use if on all but the last one where I needed to use an else if.
sfraise is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:33 AM.


Advertisement
Log in to turn off these ads.