Jump to content

[SOLVED] Help with where " should go...


Siggles

Recommended Posts

I have a good script that pulls results from a dabse and I am trying to implement a pagination script I found in the net. It works to a point but his bit of code pulls up errors because of where the "'s are placed I think...

 

if($pg > 1){ $prev = ($pg - 1); // Previous Link

$paginator ="<a href="".$_SERVER['PHP_SELF']."?pg=$prev">"Previous page</a>"; }

for($i = 1; $i <= $total_pgs; $i++){ /// Numbers

if(($pg) == $i) { $paginator .= "<i>$i</i> "; } else {

$paginator .="<a href="".$_SERVER['PHP_SELF']."?pg=$i">$i</a> "; }}

if($pg < $total_pgs){ $next = ($pg + 1); // Next Link

$paginator .="<a href="".$_SERVER['PHP_SELF']."?pg=$next">"Next page."</a>"; }

 

I don't seem to be able to get it to work. Can anyone help?

Link to comment
Share on other sites

I notice a lot of errors in the code you have displayed, firstly your double quotes are not escaped in the middle of the string, secondly you end your anchor tags with a BBcode [/ url] tag and basically the code is messy. I tend to avoid using the concatenation operator when placing variables inside strings and its usually best practice to use curly brackets. I have tidied the code up for you though I cannot guarantee your script will work as this only seems to be part of it.

 

So try this,

 

<?php

if ($pg > 1) {
// Previous Link 
$prev = $pg - 1; 
$paginator ="<a href=\"{$_SERVER['PHP_SELF']}?pg=$prev\">Previous page</a>"; 
}

//Numbers   
for($i = 1; $i <= $total_pgs; $i++) { 
   if (($pg) == $i) { 
   	$paginator .= "{$i} "; 
   } else {
   	$paginator .= "<a href=\"{$_SERVER['PHP_SELF']}?pg={$i}\">{$i}</a>"; 
   }
}
   
if ($pg < $total_pgs) {
// Next Link
   	$next = $pg + 1; 
   	$paginator .= "<a href=\"{$_SERVER['PHP_SELF']}?pg={$next}\">Next page.</a>";
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.