Jump to content

Recommended Posts

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"; 
} 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/45032-paging-of-query-result/
Share on other sites

  • 2 weeks later...

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");
?>

  • 1 month later...
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.