User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,212 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,776 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 258 | Replies: 2
Reply
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Help Can anyone give me an example of "Pagination of the results of a search query"

  #1  
Mar 11th, 2008
Hi all,

I am new to PHP.. I want to paginate the result of a search query...
can any one give me an example of the concern codes...
u can post it on daniweb or u can send it on jinojoseph07@gmail.com

Please help me..
Jino..
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 507
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 68
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Can anyone give me an example of "Pagination of the results of a search query"

  #2  
Mar 11th, 2008
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Mar 2008
Posts: 55
Reputation: forzadraco is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
forzadraco forzadraco is offline Offline
Junior Poster in Training

This is example dynamic-paging

  #3  
Mar 11th, 2008
<?php
/* paging_dinamis.php */

require_once "connection.inc.php";

echo "<form action=\"$PHP_SELF\" method=\"GET\">";
echo "<b>Number of Paging :</b>
<select name='batas'>
<option value='3'>3
<option value='5'>5
<option value='10'>10
<option value='10'>15
</select>&nbsp;";
echo "<input type=submit value='submit'>";
echo "</form>";

$flname=basename($PHP_SELF);

$res = mysql_query("SELECT * FROM table_name ORDER BY id");

$jml = @mysql_num_rows($res);
if ($jml == 0) {
echo "<font color=red>
<b>Ooops.... Data not found</b></font>";
exit;
}

// Initialization default value for paging
if (isset($_GET["batas"])) {
$batas = $_GET["batas"];
} else {
$batas = 3;
}

if (($jml % $batas) == 0) {
$jmlpage=(int)($jml/$batas);
} else {
$jmlpage=((int)$jml/$batas)+1;
}

// Inisialisasi variabel page
if (isset($_GET["page"])) {
$page = $_GET["page"];
} else {
$page = 1;
}

if ($page>$jmlpage) {
$page = $jmlpage;
}

while ($rows = mysql_fetch_array($res)) {
$arrdata[] = $rows;
}

$end = ($page*$batas)-1;
$start= $end-($batas-1);
if ($end > $jml) {
$end = $jml-1;
}

for ($i=$start; $i<=$end; $i++) {
$arr[] = $arrdata[$i];
}
echo "<table width=450 style='border:1pt solid #666666;'>";
foreach ($arr as $row) {
echo "<tr><td width=100>Nama</td>
<td width=10>:</td><td>$row[1]</td></tr>";
echo "<tr><td>Email</td><td>:</td><td>
<a href='mailtorow[2]'>$row[2]</a></td></tr>";
echo "<tr><td>Komentar</td>
<td>:</td><td>$row[3]</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
}

echo "</table> <br>";

// Manage paging navigation
for ($n=1; $n<=$jmlpage; $n++) {
$b = $page + 1;
if ($n != $page) {
echo "&nbsp;<a href='$flname?page=$n&batas=$batas'>
Hal $n</a>&nbsp;";
} else {
echo "<font color='#999999'><b>Hal $n </b></font>";
}
}

// Next navigation paging
if (($n != $page) && ($n > $b)) {
echo "&nbsp;<a href='$flname?page=$b&batas=$batas'>
Next</a>";
}
?>
</body></html>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:50 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC