Parse error with Prev/Next link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
~fleece~
Forum Newbie
Posts: 12
Joined: Sun Apr 04, 2004 10:18 pm

Parse error with Prev/Next link

Post by ~fleece~ »

I'm trying to make prev/next links for my blog pages and I have this code:

Code: Select all

if ($page_no != 1) {
	      $prev = $page_no - 1;
	      echo <<<END
                <a href="page.php?page_no=$prev">Previous</a>
END;
	 }
  if ($page_no != $pages) {
	      $next = $page_no + 1;
	      echo <<<END
                <a href="page.php?page_no=$next">Next</a>
END;
     }
But I always get a parse error at this line:

Code: Select all

<a href="page.php?page_no=$prev">Previous</a>
What am I doing wrong? :?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What does the parse error say?

Mac
~fleece~
Forum Newbie
Posts: 12
Joined: Sun Apr 04, 2004 10:18 pm

Post by ~fleece~ »

twigletmac wrote:What does the parse error say?

Mac
It just says :

Parse error: parse error in /home/httpd/virtual/domain.com/dir/page.php on line 47

Line 47 is the line which has the link. :(
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I have no clue what's wrong. I'd check your heredocs though for spaces before and after the closing heredoc.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

Does it work if you don't use the heredoc at all?

Like:

Code: Select all

if ($page_no != 1) { 
         $prev = $page_no - 1; 
         echo '<a href="page.php?page_no=' . $prev . '">Previous</a>' ;
    }
If that works, then it's probably something funky with the heredoc, like pickel suggested. Maybe you can avoid using it altogether.
Post Reply