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
https://forums.phpfreaks.com/topic/86279-solved-help-with-where-should-go/
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>";
}

?>

Archived

This topic is now archived and is closed to further replies.

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