CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [terrykhatri531] Trying to convert a php script into perl: Edit Log



Zhris
Enthusiast

Aug 25, 2014, 9:11 PM


Views: 2964
Re: [terrykhatri531] Trying to convert a php script into perl

Hi Terry,

Another pagination script Shocked!

The problem you describe is because a couple of end curly braces for a loop and condition are in the wrong places:


Code
 
if($page < 1 + ($adjacents * 2)){
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
if ($counter == $page){
$pagination.= "<a class='current'>$counter</a>";}
else{
$pagination.= "<a href='{$url}page=$counter'>$counter</a>";
$pagination.= "<span class='paging_dots'>..</span>";
$pagination.= "<a href='{$url}page=$lpm1'>$lpm1</a>";
$pagination.= "<a href='{$url}page=$lastpage'>$lastpage</a>";
}
}
}



Code
 
if ($page < 1 + ($adjacents * 2)){
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
if ($counter == $page){
$pagination.= "<a class='current'>$counter</a>";
}
else{
$pagination.= "<a href='{$url}page=$counter'>$counter</a>";
}
}
$pagination.= "<span class='paging_dots'>..</span>";
$pagination.= "<a href='{$url}page=$lpm1'>$lpm1</a>";
$pagination.= "<a href='{$url}page=$lastpage'>$lastpage</a>";
}



There are other potential issues, but i'm sure you will identify these upon testing.

Don't get me wrong, if this script gives you the desired result then absolutely do use it, but it could be greatly improved. There should be a clear separation between generating the page data and using the page data to generate the html. There is also repetition, which could be reduced using a more sophisticated algorithm and breaking the code up into specialist functions. This would also help in making it more configurable without the risk of it breaking. I would have loved to have shown you the custom written pagination code I use, but its somewhat tied in with my framework and would take considerable effort creating a standalone demo.

Regards,

Chris


(This post was edited by Zhris on Aug 25, 2014, 10:02 PM)


Edit Log:
Post edited by Zhris (Enthusiast) on Aug 25, 2014, 9:12 PM
Post edited by Zhris (Enthusiast) on Aug 25, 2014, 9:32 PM
Post edited by Zhris (Enthusiast) on Aug 25, 2014, 9:33 PM
Post edited by Zhris (Enthusiast) on Aug 25, 2014, 9:43 PM
Post edited by Zhris (Enthusiast) on Aug 25, 2014, 9:44 PM
Post edited by Zhris (Enthusiast) on Aug 25, 2014, 9:47 PM
Post edited by Zhris (Enthusiast) on Aug 25, 2014, 10:02 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives