Schlo_50 Posted May 27, 2008 Share Posted May 27, 2008 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 More sharing options...
andrew_biggart Posted May 27, 2008 Share Posted May 27, 2008 This very very hard 2 do i am not an expert but try this !!!!!!! http://www.phpeasystep.com/phptu/29.html This should help let me know how you get on Link to comment https://forums.phpfreaks.com/topic/107451-pagination/#findComment-550804 Share on other sites More sharing options...
Schlo_50 Posted May 27, 2008 Author Share Posted May 27, 2008 Cheers, Will post back. Link to comment https://forums.phpfreaks.com/topic/107451-pagination/#findComment-550812 Share on other sites More sharing options...
sasa Posted May 27, 2008 Share Posted May 27, 2008 <?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 More sharing options...
Schlo_50 Posted May 27, 2008 Author Share Posted May 27, 2008 That seems to work well, having problems implementing it into my original code though! Thanks! Link to comment https://forums.phpfreaks.com/topic/107451-pagination/#findComment-550826 Share on other sites More sharing options...
sasa Posted May 27, 2008 Share Posted May 27, 2008 what array you want to paginate Link to comment https://forums.phpfreaks.com/topic/107451-pagination/#findComment-550841 Share on other sites More sharing options...
Schlo_50 Posted May 28, 2008 Author Share Posted May 28, 2008 I'd like to paginate $find. if (in_array($find, $lookup)) { print "Match : $find"; } Link to comment https://forums.phpfreaks.com/topic/107451-pagination/#findComment-551499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.