affordit Posted February 6, 2008 Share Posted February 6, 2008 Can someone tell me how to insert a </TR> tag in the script below after each set of 5 products has been displayed I posted all the code and where the results are processed I canged the color to lime. <?php session_start(); include"client_info3.php"; include"top_mid_nav.inc"; print "<table align='center' bgcolor='#FFFF66' border='1'><tr><td>"; switch ($prod) { default: print "<table align'center'><tr><td align='center'><B> Please choose what products you'd like to look at:</td></tr></B>"; echo "<tr><td align='center'> <A HREF=random_product5.php?prod=watches>Watches</A> <A HREF=random_product5.php?prod=toys>Toys</A> <A HREF=random_product5.php?prod=batteries>Batteries</A> <A HREF=random_product5.php?prod=auto>Automotive</A> <A HREF=random_product5.php?prod=apparal>Apparal</A> <A HREF=random_product5.php?prod=housewares>Housewares</A> <A HREF=random_product5.php?prod=tools>Tools</A> <A HREF=random_product5.php?prod=hardware>Hardware</A> <A HREF=random_product5.php?prod=electronics>Electronics</A> </td></tr></table>"; } print "</td></tr></table>"; include("sharons_dbinfo.inc.php"); mysql_connect(mysql,$name,$password); mysql_select_db(mydatabase) or die( "Unable to select database"); //Count rows $query = "SELECT count(*) FROM content WHERE category = '$prod' OR featured = '1'"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $page = ( isset( $_GET['page'] ) && is_numeric( $_GET['page'] ) ) ? $_GET['page'] : 1; $query = "SELECT count(*) FROM content WHERE category = '$prod' OR featured = '1'"; $result = mysql_query( $query ); $fetch = mysql_fetch_row( $result ); $numRows = $fetch[0]; $rowsPerPage = ( isset( $_GET['show'] ) && is_numeric( $_GET['show'] && $_GET['show'] >= 1 ) && $_GET['show'] <= 40 ) ? $_GET['show'] : 20; $lastPage = ceil( $numRows / $rowsPerPage ); $page = (int)$page; if( $page < 1 ) { $page = 1; } elseif( $page > $lastPage ) { $page = $lastPage; } if( $numRows > 0 ) $limit = 'LIMIT ' . ( $page - 1 ) * $rowsPerPage . ',' . $rowsPerPage; else $limit = ''; //Query the DB $query = "SELECT * FROM content WHERE category = '$prod' OR featured = '1' $limit"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); [color=limegreen]// PROCESS CONTENTS OF $RESULTS print "<table width='700' align='center'><tr>"; if(!isset($prod) ){ print "<TR><TD colspan='10' align='center'><h3>Showing Featured Items</h3></TD></TR>"; } else { print "<TR><TD colspan='10' align='center'><h3>Showing $prod and Featured Items</h3></TD></TR>"; } while ($info = mysql_fetch_array($result)) { print "<td width='0' ALIGN='CENTER'>"; echo $info['heading']; echo "<BR>"; echo $info['picture']; echo "<BR>"; echo $info['description']; echo"<BR></td>"; }[/color] $lastPage = (int)$lastPage; ?> <table width="100%" bgcolor="#FFFF66" cellspacing="0" border="1"> <tr> <?php if ( $page == 1 ) { ?> <td align="center" width="15%" style="padding:0;"> <a href="#">First</a> | <a href="#">Previous</a> </td> <?php } else { $prevPage = $page - 1; ?> <td align="center" width="15%" style="padding:0;"> <a href="?prod=<?php echo ($_GET['prod']); ?>&id=&page=<?php echo( 1 ); ?>">First</a> | <a href="?prod=<?php echo ($_GET['prod']); ?>&id=&page=<?php echo( $prevPage ); ?>">Previous</a> </td> <?php } $totalPages = $lastPage; $curentPage = $page; if ( $totalPages < 8 ) { $start = 1; $end = $totalPages; } else { if ( $curentPage > 3 ) { if ( $totalPages - $curentPage < 3 ) $end = $totalPages; else $end = $curentPage + 3; $start = $end - 6; } else { $start = 1; $end = 7; } } ?> <td width="70%" class="black_td" style="padding:0;text-align:center;"> <?php echo( '<strong>Page:</strong> ' ); if ( $start > 1 ) echo ' ... '; for ( $i = $start; $i <= $end; $i++ ) { if ( $i == $curentPage ) echo( '<span style="font-weight:bold;">' . $i . '</span>' ); else echo ' <a href="?prod=' . $_GET['prod'] . '&id=' . $_GET['id'] . '&page=' . $i . '" style="font-size:1.00em;">' . $i . '</a> '; } if ( $end < $totalPages ) echo ' ... '; echo( "<strong> of {$totalPages}</strong>" ); ?> </td> <?php if ($page == $lastPage) { ?> <td align="center" width="15%" style="padding:0;"> Next | Last </td> <?php } else { $nextPage = $page + 1; ?> <td align="center" width="15%"> <a href="?prod=<?php echo ($_GET['prod']); ?>&id=&page=<?php echo( $nextPage ); ?>">Next</a> | <a href="?prod=<?php echo ($_GET['prod']); ?>&id=&page=<?php echo( $lastPage ); ?>">Last</a> </td> <?php } print "<table align='center' border='1'><tr><td>"; switch ($prod) { default: print "<table align'center' bgcolor='#FFFF66'><tr><td align='center'><B> Please choose what products you'd like to look at:</td></tr></B>"; echo "<tr><td align='center'> <A HREF=random_product5.php?prod=watches>Watches</A> <A HREF=random_product5.php?prod=toys>Toys</A> <A HREF=random_product5.php?prod=batteries>Batteries</A> <A HREF=random_product5.php?prod=auto>Automotive</A> <A HREF=random_product5.php?prod=apparal>Apparal</A> <A HREF=random_product5.php?prod=housewares>Housewares</A> <A HREF=random_product5.php?prod=tools>Tools</A> <A HREF=random_product5.php?prod=hardware>Hardware</A> <A HREF=random_product5.php?prod=electronics>Electronics</A> </td></tr></table>"; } print "</td></tr></table>"; ?> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/89785-solved-pagination-question/ Share on other sites More sharing options...
affordit Posted February 6, 2008 Author Share Posted February 6, 2008 Well I tried to turn it green Link to comment https://forums.phpfreaks.com/topic/89785-solved-pagination-question/#findComment-460058 Share on other sites More sharing options...
rhodesa Posted February 6, 2008 Share Posted February 6, 2008 I think this is what you are looking for: $i = 0; while ($info = mysql_fetch_array($result)) { print "<td width='0' ALIGN='CENTER'>"; echo $info['heading']; echo "<BR>"; echo $info['picture']; echo "<BR>"; echo $info['description']; echo"<BR></td>"; $i++; if($i % 5 == 0){ echo "</tr><tr>"; } } Link to comment https://forums.phpfreaks.com/topic/89785-solved-pagination-question/#findComment-460068 Share on other sites More sharing options...
affordit Posted February 6, 2008 Author Share Posted February 6, 2008 That still runs all the results accross the top of the screen Link to comment https://forums.phpfreaks.com/topic/89785-solved-pagination-question/#findComment-460075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.