TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 04-08-2009, 10:29 PM   #1 (permalink)
The Contributor
 
WebSavvy's Avatar
 
Join Date: Mar 2009
Location: Springfield, IL USA
Posts: 75
Thanks: 3
WebSavvy is on a distinguished road
Default Php & MySql Pagination Script

Code:
<?php

$newp = $_GET['p'];
$plimit = "10";

$strSQL = mysql_query("SELECT * FROM `your_table` WHERE(`field1` LIKE \"$variable%\" AND `field2`=\"whatever\")");

$totalrows = mysql_num_rows($strSQL);
$pnums = ceil ($totalrows/$plimit);

if ($newp==''){ $newp='1'; }

$start = ($newp-1) * $plimit;
$starting_no = $start + 1;

if ($totalrows - $start < $plimit) { $end_count = $totalrows;
} elseif ($totalrows - $start >= $plimit) { $end_count = $start + $plimit; }

?>

<div>viewing <?php print_r("$starting_no");?> - <?php print_r("$end_count");?> of <?php print_r("$totalrows");?> entries</div>

<?php

if ($totalrows - $end_count > $plimit) { $var2 = $plimit;
} elseif ($totalrows - $end_count <= $plimit) { $var2 = $totalrows - $end_count; }

?>

<ul>
   <li id="pages">pages: </li>
<?php if ($newp>1) { ?>
   <li><a href="<?php echo "http://yourdomain.com/page.php?p=".($newp-1);?>">&laquo;</a></li>
<?php } for ($i=1; $i<=$pnums; $i++) { if ($i!=$newp){ ?>
   <li><a href="<?php echo "http://yourdomain.com/page.php?p=$i";?>"><?php print_r("$i");?></a></li>
<?php } else { ?>
   <li id="current"><?php print_r("$i");?></li>
<?php }} if ($newp<$pnums) { ?>
   <li><a href="<?php echo "http://yourdomain.com/page.php?p=".($newp+1);?>">&raquo;</a></li>
<?php } ?>
</ul>


<ul>
<?php

$strSQL = mysql_query("SELECT `field1`, `field2`, `field3`, `field4` FROM `your_table` WHERE(`field1`=\"whatever\" AND `field2`=\"that\") ORDER BY `field1` DESC, `field2` ASC LIMIT $start,$plimit");

while ($row = mysql_fetch_array($strSQL)) {
   $field1 = $row["field1"];
   $field2 = $row["field2"];
   $field3 = $row["field3"];
   $field4 = $row["field4"];

?>

   <li>This is all I know about <?=$field1?> and <?=$field2?> ... though <?=$field3?> and <?=$field4?> interest me too.</li>

<?php 
}//END SQL
?>

</ul>
WebSavvy is offline  
Reply With Quote
The Following User Says Thank You to WebSavvy For This Useful Post:
Brook (04-10-2009)
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on PHP MYSQL Forms Input deesudesu Absolute Beginners 1 03-20-2009 10:50 AM
Basic php form update mysql script dp2 Absolute Beginners 3 03-11-2009 04:06 PM
Nginx Rewrite Causing Wrong Path for PHP Script stewart General 0 11-09-2008 12:32 AM
Securing your MySQL Queries with Sprintf Wildhoney General 26 03-18-2008 06:52 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM


All times are GMT. The time now is 11:26 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design