Go Back   Novahq.net Forum > phphq.Net > phphq.Net Forums
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-02-2005, 12:37 AM
PHP-Largo
Unregistered

Posts: n/a

Pagination

I want it for every 15 rows pulled out of the mysql table to create a new page, to show another, but i'm not quite sure how...i know it probaly uses a for loop, please help!
Reply With Quote
  #2  
Old 03-24-2005, 02:58 AM
B Freddy Berg
Unregistered

Posts: n/a

I can show you how in Dreamweaver MX....but straight code no. Here's a demo of what it makes for me:


[code:1:8ac1ff68b6]<?php require_once('Connections/dbConn.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_news = 3; // number of rows <---
$pageNum_news = 0;
if (isset($_GET['pageNum_news'])) {
$pageNum_news = $_GET['pageNum_news'];
}
$startRow_news = $pageNum_news * $maxRows_news;

mysql_select_db($database_dbConn, $dbConn);
$query_news = "SELECT * FROM news ORDER BY id DESC";
$query_limit_news = sprintf("%s LIMIT %d, %d", $query_news, $startRow_news, $maxRows_news);
$news = mysql_query($query_limit_news, $dbConn) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);

if (isset($_GET['totalRows_news'])) {
$totalRows_news = $_GET['totalRows_news'];
} else {
$all_news = mysql_query($query_news);
$totalRows_news = mysql_num_rows($all_news);
}
$totalPages_news = ceil($totalRows_news/$maxRows_news)-1;

$queryString_news = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_news") == false &&
stristr($param, "totalRows_news") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_news = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_news = sprintf("&totalRows_news=%d%s", $totalRows_news, $queryString_news);
?>
<html>
....
<body>
Here's the first previous next and last page things
<a href="<?php printf("%s?pageNum_news=%d%s", $currentPage, 0, $queryString_news); ?>">First</a> - <a href="<?php printf("%s?pageNum_news=%d%s", $currentPage, max(0, $pageNum_news - 1), $queryString_news); ?>">Previous</a> - <a href="<?php printf("%s?pageNum_news=%d%s", $currentPage, min($totalPages_news, $pageNum_news + 1), $queryString_news); ?>">Next</a> - <a href="<?php printf("%s?pageNum_news=%d%s", $currentPage, $totalPages_news, $queryString_news); ?>">Last</a>


<?php do { ?>
<table width="89%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" class="news"><?php echo $row_news['title']; ?></td>
</tr>
<tr>
<td colspan="2" class="text1"><?php echo $row_news['body']; ?></td>
</tr>
<tr>
<td width="51%" class="news"><?php echo $row_news['date']; ?></td>
<td width="40%" class="news">-<?php echo $row_news['author']; ?></td>
</tr>
</table>
<?php } while ($row_news = mysql_fetch_assoc($news)); ?>

</body>
</html>
<?php
mysql_free_result($news);
?>[/code:1:8ac1ff68b6]


talk to me on aim "bfreddyberg" and I'll show u how in DW
Reply With Quote
  #3  
Old 03-24-2005, 03:02 AM
brian
Unregistered

Posts: n/a

that was me, thought I was logged in :?
Reply With Quote
Reply


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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a pagination system? Guest phphq.Net Forums 1 10-11-2004 05:46 PM


All times are GMT -5. The time now is 12:02 PM.




Powered by vBulletin®