Jump to content

[SOLVED] Paginition


Daney11

Recommended Posts

Hey guys,

 

This is both, PHP and HTML and is not getting on my nerves and im not sure how to crack it. It is to do with paginition.

 

Snipplet of the code thats the problem:

$pagination = '<table class="resultstable" width="508"><tr><td>'; 

/* Create a PREV link if there is one */ 
if($page > 1) 
{ 
$pagination .= ' <a href="coverage.php?page='.$prev.'">Previous </a> '; 
} 

/* Loop through the total pages */ 
for($i = 1; $i <= $total_pages; $i++) 
{ 
if(($page) == $i) 
{ 
$pagination .= ''.$i.''; 
} 
else 
{ 
$pagination .= ' <a href="coverage.php?page='.$i.'">'.$i.'</a> '; 
} 
} 

/* Print NEXT link if there is one */ 
if($page < $total_pages) 
{ 
$pagination .= ' <a href="coverage.php?page='.$next.'">Next </a> </td></tr></table>'; 
} 

 

Now if i have 3 entrys in my database and i have limited the totalrows per page to 1 i should have

 

1 2 3 Next

Previous 1 2 3 Next

1 2 3 Previous

 

NOW THE PROBLEM

 

1 2 3 Next  || Displays Perfect inside a box underneath.

Previous 1 2 3 || Display Perfect inside the box underneath.

1 2 3 Previous || Totally breaks up my website.

 

Now i know were the problem lies...

 

// Starts The Box for the Pagination

$pagination = '<table class="resultstable" width="508"><tr><td>'; 

 

//End The Box for Pagination

if($page < $total_pages) 
{ 
$pagination .= ' <a href="coverage.php?page='.$next.'">Next </a> </td></tr></table>'; 
} 

 

So as you can see, When the event Next is there the table closes. But when its "Previous 1 2 3" is there, there is no Next so the table cannot close so the table close needs to go

for($i = 1; $i <= $total_pages; $i++) 
{ 
if(($page) == $i) 
{ 
$pagination .= ''.$i.'[b]</td></tr></table>[/b]'; 
} 

 

However, if placing the code there, the page breaks when both Next and Previous are in use.

 

This has totally baffeled me.

 

Any help would be great.

 

Thanks guys

 

Dane

Link to comment
Share on other sites

I know some of you was looking at this problem for a while and didnt reply.

 

However i have it working now. All i needed to do was add a elseif

 

for($i = 1; $i <= $total_pages; $i++) 
{ 
if ($page == $i && $page == $total_pages) {
$pagination .= '['.$i.']</td></tr></table>'; 
}
elseif(($page) == $i) 
{ 
$pagination .= '['.$i.']'; 
} 
else 
{ 
$pagination .= ' <a href="coverage.php?page='.$i.'">'.$i.'</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.