Jump to content

Recommended Posts

Hi there,

 

I think what I want is called pagination? Basically, I have a very long list which I would like to break down into page numbers for faster loading and better searching. The code I have already to generate the list is below however I need some help, advice or snippets of how to implement what I need into the existing code.

 

$lines = file("data/sub_categories.DAT");
foreach ($lines as $line) { 
$data = explode("|", $line);
$lookup[] = trim($data[2]);
}

$linesb = file("data/threads.DAT");
foreach ($linesb as $lineb) { 
$datab = explode("|", $lineb);

	  $name = trim($datab[0]);
	  $pid = trim($datab[1]);
	  $category = trim($datab[2]);
	  $reference = trim($datab[3]);

$name = trim($datab[0]);
$find = trim($datab[2]);

if (in_array($find, $lookup))
{

  print "Match : Find";

}

}

 

Can any body shed some light on this much need module?

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/107451-pagination/
Share on other sites

<?php
$a = range('a', 'z'); // create list of data use your array here
$per_page = 5;
$a = array_chunk($a, $per_page);
$total_pages = count($a);
if (isset($_GET['page'])) $curent_page = $_GET['page'] + 0; else $curent_page = 1;
if ($curent_page < 0) $curent_page = 0;
if ($curent_page > $total_pages) $curent_page = $total_pages;
$curent_data = $a[$curent_page - 1];
// echo data
foreach ($curent_data as $data){
echo $data, "<br />\n";
}
// page links
if ($curent_page > 1) echo "<a href='?page=",$curent_page-1,"'> PREV </a>\n";
for ($i = 1; $i <= $total_pages; $i++){
if ($i == $curent_page) echo " $i \n";
else echo "<a href='?page=$i' > $i </a>\n";
}
if ($curent_page < $total_pages) echo "<a href='?page=",$curent_page+1,"'> NEXT </a>\n";

Link to comment
https://forums.phpfreaks.com/topic/107451-pagination/#findComment-550819
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.