washinb Posted March 31, 2007 Share Posted March 31, 2007 This script used to be working in splitting query result into pages. But now, PREV 1 2 3 4 NEXT links is not working anymore. Any idea how to fix this ? or what is wrong with this script ? Comments are highly appreciated. thanks, -bw <? if ($offset!=0) { // Jangan cetak PREV apabila offset sama dengan 0 $prevoffset=$offset-10; print "<a style=\"font-size: 120%;\" href=\"$PHP_SELF?offset=$prevoffset\">PREVIOUS</a> \n"; } // Hitung jumlah halaman & Hasil diintegerkan $halaman=intval($numrows/$limit); // $halaman sekarang berisi jumlah halaman apabila tidak ada sisa if ($numrows%$limit) { // Jika ada sisa maka jumlah halaman ditambah 1 $halaman++; } for ($i=1;$i<=$halaman;$i++) { // looping dimulai 1 $newoffset=$limit*($i-1); if ($newoffset == $offset) { print "<a style=\"font-size: 120%; color: #000000; font-weight: bold;\"> $i </a> \n"; } else { print "<a style=\"font-size: 120%;\" href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n"; } } // cek apabila telah sampai halaman terakhir if (!(($offset/$limit)+1==$halaman) && $halaman!=1) { // Jika bukan halaman terakhir, maka berikan link NEXT $newoffset=$offset+$limit; print "<a style=\"font-size: 120%;\" href=\"$PHP_SELF?offset=$newoffset\">NEXT</a>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45032-paging-of-query-result/ Share on other sites More sharing options...
washinb Posted April 11, 2007 Author Share Posted April 11, 2007 This is the script that will call the other one. <?php // includes include("../conf.php"); include("../functions.php"); // open database connection $connection = mysql_connect($host, $user, $pass) or die ("sori..., gue lagi ngga' bisa konek ke database"); // select database mysql_select_db($db) or die ("sori..., gue ngga' bisa milih database"); $limit=10; // limit tiap halaman $numresults=mysql_query("SELECT id FROM english"); $numrows=mysql_num_rows($numresults); // next akan muncul apabila offset telah dimasukkan, jika tidak maka diisi 1 if (empty($offset)) { $offset=0; } // ambil hasil $result = mysql_query("SELECT id, contact, slug, timestamp FROM english ORDER BY timestamp DESC LIMIT $offset, $limit") or die ("salah query : $query. " . mysql_error()); // Tampilkan hasil /* while ($data=mysql_fetch_array($result)) { */ // kode yang akan dijalankan while($row = mysql_fetch_object($result)) { ?> <li style=" list-style: none;"> <a id="judul" href="e_story.php?id=<? echo $row->id; ?>"><? echo $row->slug; ?></a><br> <li style=" padding-bottom: .8em; font-size: 75%; list-style: none; font-family: verdana;">Published on <? echo formatDate($row->timestamp); ?> - Source : <font color="green"><? echo $row->contact; ?></font> <? } include("paging.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/45032-paging-of-query-result/#findComment-226789 Share on other sites More sharing options...
gluck Posted April 11, 2007 Share Posted April 11, 2007 Paste the error. If you haven't changed anything in your script then it should be the Database. Quote Link to comment https://forums.phpfreaks.com/topic/45032-paging-of-query-result/#findComment-226944 Share on other sites More sharing options...
vyk2rr Posted May 30, 2007 Share Posted May 30, 2007 you can use Digg Style Pagination Class Quote Link to comment https://forums.phpfreaks.com/topic/45032-paging-of-query-result/#findComment-265084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.