Repeating Records Help Help
09-21-05, 02:34 PM
Wannabe Coder
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Repeating Records Help Help
http://alteredimage.com/testsite/newsarchives.php
here you guys can see what i`m trying to do. ( basically next page with 10 records max on each page ) the problem as you can see is its repeating the records to every page.
PHP Code:
<?php require_once( 'Connections/oconn.php' );
// 03-10-01
$today2 = date ( 'Ymd' );
$spitrecords = '999999999999999999999' ;
$currentPage = $_SERVER [ "PHP_SELF" ];
$maxRows_news = 10 ;
$pageNum_news = 0 ;
if (isset( $_GET [ 'pageNum_news' ])) {
$pageNum_news = $_GET [ 'pageNum_news' ];
}
$startRow_news = $pageNum_news * $maxRows_news ;
mysql_select_db ( $database_oconn , $oconn );
$query_news = "SELECT * FROM news" ;
$query_news = "SELECT id, headline, content, date_format(date, '%c-%d-%y') as 'date_f' FROM news WHERE date <= $today2 ORDER by date DESC LIMIT 10, $spitrecords " ;
$news = mysql_query ( $query_news , $oconn ) 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>
<head>
<title>altered image news archives</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.copyright { font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #999999;
text-decoration: none;
}
-->
</style>
<?
require_once( 'rollover1.php' );
?>
</head>
<?
require_once( 'rollover2.php' );
?>
<tr>
<td height="23" align="center" valign="top" bgcolor="#000000"><img src="images/flashholder.jpg" width="748" height="258"></td>
</tr>
<tr>
<td height="88" align="center" valign="top"><table width="755" height="88" border="0" cellpadding="8" cellspacing="8">
<tr>
<td height="72" align="left" valign="top" class="content"><p class="content">
<?php do { ?>
<strong><?php echo $row_news [ 'headline' ]; ?> </strong><br>
<?php echo $row_news [ 'content' ]; ?> <br>
<br>
<?php } while ( $row_news = mysql_fetch_assoc ( $news )); ?>
<br>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center">
<?php if ( $pageNum_news > 0 ) { // Show if not first page ?>
<a href="<?php printf ( "%s?pageNum_news=%d%s" , $currentPage , 0 , $queryString_news ); ?> ">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center">
<?php if ( $pageNum_news > 0 ) { // Show if not first page ?>
<a href="<?php printf ( "%s?pageNum_news=%d%s" , $currentPage , max ( 0 , $pageNum_news - 1 ), $queryString_news ); ?> ">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center">
<?php if ( $pageNum_news < $totalPages_news ) { // Show if not last page ?>
<a href="<?php printf ( "%s?pageNum_news=%d%s" , $currentPage , min ( $totalPages_news , $pageNum_news + 1 ), $queryString_news ); ?> ">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center">
<?php if ( $pageNum_news < $totalPages_news ) { // Show if not last page ?>
<a href="<?php printf ( "%s?pageNum_news=%d%s" , $currentPage , $totalPages_news , $queryString_news ); ?> ">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
<br>
<a href="news.php">< Back to News</a> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="35" align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="18" align="center" valign="middle"><span class="copyright">© 2005 Altered Image. All Rights Reserved.</span></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
also any suggestions on where to find a tutorial for showing page numbers for a nav like this.
Thanks Again
Tom
09-21-05, 09:01 PM
Newbie Coder
Join Date: Sep 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by tommyc325
http://alteredimage.com/testsite/newsarchives.php
here you guys can see what i`m trying to do. ( basically next page with 10 records max on each page ) the problem as you can see is its repeating the records to every page.
PHP Code:
<?php require_once( 'Connections/oconn.php' );
// 03-10-01
$today2 = date ( 'Ymd' );
$spitrecords = '999999999999999999999' ;
$currentPage = $_SERVER [ "PHP_SELF" ];
$maxRows_news = 10 ;
$pageNum_news = 0 ;
if (isset( $_GET [ 'pageNum_news' ])) {
$pageNum_news = $_GET [ 'pageNum_news' ];
}
$startRow_news = $pageNum_news * $maxRows_news ;
mysql_select_db ( $database_oconn , $oconn );
$query_news = "SELECT * FROM news" ;
$query_news = "SELECT id, headline, content, date_format(date, '%c-%d-%y') as 'date_f' FROM news WHERE date <= $today2 ORDER by date DESC LIMIT 10, $spitrecords " ;
$news = mysql_query ( $query_news , $oconn ) 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>
<head>
<title>altered image news archives</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.copyright { font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #999999;
text-decoration: none;
}
-->
</style>
<?
require_once( 'rollover1.php' );
?>
</head>
<?
require_once( 'rollover2.php' );
?>
<tr>
<td height="23" align="center" valign="top" bgcolor="#000000"><img src="images/flashholder.jpg" width="748" height="258"></td>
</tr>
<tr>
<td height="88" align="center" valign="top"><table width="755" height="88" border="0" cellpadding="8" cellspacing="8">
<tr>
<td height="72" align="left" valign="top" class="content"><p class="content">
<?php do { ?>
<strong><?php echo $row_news [ 'headline' ]; ?> </strong><br>
<?php echo $row_news [ 'content' ]; ?> <br>
<br>
<?php } while ( $row_news = mysql_fetch_assoc ( $news )); ?>
<br>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center">
<?php if ( $pageNum_news > 0 ) { // Show if not first page ?>
<a href="<?php printf ( "%s?pageNum_news=%d%s" , $currentPage , 0 , $queryString_news ); ?> ">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center">
<?php if ( $pageNum_news > 0 ) { // Show if not first page ?>
<a href="<?php printf ( "%s?pageNum_news=%d%s" , $currentPage , max ( 0 , $pageNum_news - 1 ), $queryString_news ); ?> ">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center">
<?php if ( $pageNum_news < $totalPages_news ) { // Show if not last page ?>
<a href="<?php printf ( "%s?pageNum_news=%d%s" , $currentPage , min ( $totalPages_news , $pageNum_news + 1 ), $queryString_news ); ?> ">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center">
<?php if ( $pageNum_news < $totalPages_news ) { // Show if not last page ?>
<a href="<?php printf ( "%s?pageNum_news=%d%s" , $currentPage , $totalPages_news , $queryString_news ); ?> ">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
<br>
<a href="news.php">< Back to News</a> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="35" align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="18" align="center" valign="middle"><span class="copyright">© 2005 Altered Image. All Rights Reserved.</span></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
also any suggestions on where to find a tutorial for showing page numbers for a nav like this.
Thanks Again
Tom
Hi Tom!
Here's a
Link
__________________
Happy coding!
----------------------------
http://www.jusupov.com - Computer Technology Blog
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off