stubyh Posted November 3, 2006 Share Posted November 3, 2006 Hi I have two problems in the following code and need help 1) I have a DB with 18 items in it and would only like to display the first 10 on each page, but it's not working I only get 1 page with all items listed. 2) the first record is not displayed only items displayed are displayed 2 - 18 Thanks[code] <? include("templates/header.php"); ?><?php // get the data from the database require_once('Connections/banners.php'); // Number of records to show per page:$display = 10;// Determine how many pages there are. if (isset($_GET['np'])) { // Already been determined. $num_pages = $_GET['np'];} else { // Need to determine. $get_ids_sql = "SELECT id, link AS url, alt_title, image FROM banners WHERE status = 'on'"; $get_ids_res = mysql_query ($get_ids_sql); $row = mysql_fetch_array($get_ids_res, MYSQL_NUM); $num_records = $row[0]; // check the output - remove after fixecho $num_records;echo $display; // end check // Calculate the number of pages. if ($num_records > $display) { // More than 1 page. $num_pages = ceil($num_records/$display); } else { $num_pages = 1; } } // End of np IF. // create the page for realecho '<body bgcolor="#FFFFFF" text="#000000" link="#003399" vlink="#003399" alink="#CC0000">';echo '</td> <table width=80% height=100% align="center" border=0 cellpadding=0 cellspacing=0 ><tr><td width=75% height=100%> </td><td valign=top bgcolor=#FFFFFF><table cellspacing="0" cellpadding="0" border="0" width="791" height=100%> <tr><td colspan="2" rowspan="2" valign="top" align="center"><table cellspacing="0" cellpadding="10" border="0">'; // Fetch and print all the records.while ($row = mysql_fetch_array($get_ids_res, MYSQL_ASSOC)) {// remove the {$row['id']} in echo statement after fixecho ' <tr><td width="770" align="center"> <table cellspacing="0" cellpadding="0" border="0" width="680"> <tr><td> <table cellspacing="0" cellpadding="6" border="0" width="680"> <tr> <td bgcolor="#FFFFFF" align="center">'; echo "<a href=\"{$row['url']}\"><img src=\"/banner/bannerimages/{$row['image']}\" alt=\"{$row['alt_title']}\" border=\"0\">{$row['id']}</p>"; echo '</td> </tr> </table> </td> <td bgcolor="#C2C2C2"><img src="spacer.gif" width="2" height="1" border="0"></td></tr> <tr><td bgcolor="#C2C2C2"><img src="spacer.gif" width="1" height="2" border="0"></td> <td bgcolor="#C2C2C2"><img src="spacer.gif" width="1" height="1" border="0"></td></tr> </table></td>';}?><td width=50% height=100%> </td></tr></table><p> </p></table><?// Make the links to other pages, if necessary.if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="index3.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="index3.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="index3.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>'; } echo '</p>'; } // End of links section.?> <? include("templates/footer.php"); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/26084-solved-need-some-help-on-missing-record-and-page-numbers/ Share on other sites More sharing options...
stubyh Posted November 3, 2006 Author Share Posted November 3, 2006 Hi OK solved problem (2) and sorry missed some code out from the first, It now only displays the first 10 (thats good) but the next page links are not showing (that's bad)any ideas ??? new code[code] <? include("templates/header.php"); ?><?php // get the data from the database require_once('Connections/banners.php'); // Number of records to show per page:$display = 10;// Determine how many pages there are. if (isset($_GET['np'])) { // Already been determined. $num_pages = $_GET['np'];} else { // Need to determine. $get_ids_sql = "SELECT COUNT(*) FROM banners"; $get_ids_res = mysql_query ($get_ids_sql); $row = mysql_fetch_array($get_ids_res, MYSQL_NUM); $num_records = $row[0]; // check the output - remove after fixecho $num_records;echo $display; // end check // Calculate the number of pages. if ($num_records > $display) { // More than 1 page. $num_pages = ceil($num_records/$display); } else { $num_pages = 1; } } // End of np IF. // Determine where in the database to start returning results.if (isset($_GET['s'])) { $start = $_GET['s'];} else { $start = 0;} $get_ids_sql = "SELECT id, link AS url, alt_title, image FROM banners WHERE status = 'on'LIMIT $start, $display"; $get_ids_res = mysql_query ($get_ids_sql);// create the page for realecho '<body bgcolor="#FFFFFF" text="#000000" link="#003399" vlink="#003399" alink="#CC0000">';echo '</td> <table width=80% height=100% align="center" border=0 cellpadding=0 cellspacing=0 ><tr><td width=75% height=100%> </td><td valign=top bgcolor=#FFFFFF><table cellspacing="0" cellpadding="0" border="0" width="791" height=100%> <tr><td colspan="2" rowspan="2" valign="top" align="center"><table cellspacing="0" cellpadding="10" border="0">'; // Fetch and print all the records.while ($row = mysql_fetch_array($get_ids_res, MYSQL_ASSOC)) {// remove the {$row['id']} in echo statement after fixecho ' <tr><td width="770" align="center"> <table cellspacing="0" cellpadding="0" border="0" width="680"> <tr><td> <table cellspacing="0" cellpadding="6" border="0" width="680"> <tr> <td bgcolor="#FFFFFF" align="center">'; echo "<a href=\"{$row['url']}\"><img src=\"/banner/bannerimages/{$row['image']}\" alt=\"{$row['alt_title']}\" border=\"0\">{$row['id']}</p>"; echo '</td> </tr> </table> </td> <td bgcolor="#C2C2C2"><img src="spacer.gif" width="2" height="1" border="0"></td></tr> <tr><td bgcolor="#C2C2C2"><img src="spacer.gif" width="1" height="2" border="0"></td> <td bgcolor="#C2C2C2"><img src="spacer.gif" width="1" height="1" border="0"></td></tr> </table></td>';}mysql_free_result ($get_ids_res); // Free up the resources. mysql_close(); // Close the database connection.?><td width=50% height=100%> </td></tr></table><p> </p></table><?// Make the links to other pages, if necessary.if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="index3.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="index3.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="index3.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>'; } echo '</p>'; } // End of links section.?> <? include("templates/footer.php"); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/26084-solved-need-some-help-on-missing-record-and-page-numbers/#findComment-119264 Share on other sites More sharing options...
Orio Posted November 3, 2006 Share Posted November 3, 2006 Why do you have this condition in the beging of the links part?if ($num_pages > 1)Orio. Link to comment https://forums.phpfreaks.com/topic/26084-solved-need-some-help-on-missing-record-and-page-numbers/#findComment-119265 Share on other sites More sharing options...
stubyh Posted November 3, 2006 Author Share Posted November 3, 2006 $num_pages is set at line 32 (macromedia) so if there is more than one page do this code if not don't bother wasting time just jump to the end. I may be wrong in doing this....stubyh Link to comment https://forums.phpfreaks.com/topic/26084-solved-need-some-help-on-missing-record-and-page-numbers/#findComment-119277 Share on other sites More sharing options...
Orio Posted November 3, 2006 Share Posted November 3, 2006 I think it shouldnt be there. Page 1 should also have links.Orio. Link to comment https://forums.phpfreaks.com/topic/26084-solved-need-some-help-on-missing-record-and-page-numbers/#findComment-119282 Share on other sites More sharing options...
stubyh Posted November 3, 2006 Author Share Posted November 3, 2006 True but what if there are only 10 items to be displayed then no need for a next page button. only need button if there are 11 or more. the SQL code will eventually be driven from a search, but I'm a long way off from that. stubyh Link to comment https://forums.phpfreaks.com/topic/26084-solved-need-some-help-on-missing-record-and-page-numbers/#findComment-119289 Share on other sites More sharing options...
stubyh Posted November 3, 2006 Author Share Posted November 3, 2006 I have solved the problem, below is listed the code.[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><? include("templates/header.php"); ?><table width="100%" border="0" cellpadding="1"> <tr> <td width=20%> </td> <td width=60%> <?php // get the data from the database require_once('Connections/banners.php'); // Number of records to show per page:$display = 10;// Determine how many pages there are. if (isset($_GET['np'])) { // Already been determined. $num_pages = $_GET['np'];} else { // Need to determine. $get_ids_sql = "SELECT COUNT(*) FROM banners"; $get_ids_res = mysql_query ($get_ids_sql); $row = mysql_fetch_array($get_ids_res, MYSQL_NUM); $num_records = $row[0]; // Calculate the number of pages. if ($num_records > $display) { // More than 1 page. $num_pages = ceil($num_records/$display); } else { $num_pages = 1; } } // End of np IF. // Determine where in the database to start returning results.if (isset($_GET['s'])) { $start = $_GET['s'];} else { $start = 0;} $get_ids_sql = "SELECT id, link AS url, alt_title, image FROM banners WHERE status = 'on'LIMIT $start, $display"; $get_ids_res = mysql_query ($get_ids_sql); // Fetch and print all the records.while ($row = mysql_fetch_array($get_ids_res, MYSQL_ASSOC)) { echo "<a href=\"{$row['url']}\"><img src=\"/banner/bannerimages/{$row['image']}\" alt=\"{$row['alt_title']}\" border=\"0\"></p>"; }mysql_free_result ($get_ids_res); // Free up the resources. mysql_close(); // Close the database connection.?> </td> <td width=20%> </td> </tr></table><table width="200" border="0" cellpadding="1"> <tr> <td><?// Make the links to other pages, if necessary.if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; echo 'Page >> '; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="index4.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="index4.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="index4.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>'; } } // End of links section.?></td> </tr></table><? include("templates/footer.php"); ?><p> </p></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/26084-solved-need-some-help-on-missing-record-and-page-numbers/#findComment-119361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.