limit the amount of results on a page
Posted: Mon Jul 17, 2006 2:57 am
Hi I hope someone can help, I only want to display three results per page or the option to change the amount, and it was working until I started messing round with the display of the artists details and craft titles. I think it's because I've got two new select statments where I'm calling my data from so it's ignoring the records code? Not sure how to rectify the problem
If anyone can help it would be greatly appreciated. Here's the code:
Thank you
If anyone can help it would be greatly appreciated. Here's the code:
Code: Select all
<?php
// Set the page title and include the HTML header.
$page_title = 'Staffordshire Open Studios - Artists Listings';
include_once ('includes/header_directory.html');
require_once ('../mysql_connect.php'); // Connect to the database.
// Number of records to show per page:
$display = 3;
// Determine how many pages there are.
if (isset($_GET['np'])) { // Already been determined.
$num_pages = $_GET['np'];
} else { // Need to determine.
$query = "SELECT * FROM artists ORDER by _craftId ASC"; // Standard query.
$query_result = mysql_query ($query);
$num_records = mysql_num_rows ($query_result);
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}
// Determine where in the database to start returning results.
if (isset($_GET['s'])) { // Already been determined.
$start = $_GET['s'];
} else {
$start = 0;
}
// Make the query.
$query = "SELECT * FROM artists ORDER by _craftId ASC LIMIT $start, $display";
$result = mysql_query ($query); // Run the query.
$num = mysql_num_rows ($result); // How many artists are there?
if ($num > 0) { // If it ran OK, display the records.
echo "<h1>ARTISTS LISTINGS</h1><span class=\"small\">Details of other artists operating in the County of Staffordshire.<br><br></span>";
// Make the links to other pages, if necessary.
if ($num_pages > 1) {
echo '<table width="100%" align="right"><tr><td align="right">';
// Determine what page the script is on.
$current_page = ($start / $display) + 1;
echo'<table align="right"><tr>';
// If it's not the first page, make a Previous button.
if ($current_page !=1) {
echo '<td align="right"> <a href="artists_listings.php?s=' . ($start - $display) . '&np=' . $num_pages . '"><img src="images/arrow_left.jpg" width="28" height="34" border="0"></a> </td>';
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
echo '<td align="center">';
if ($i != $current_page) {
echo ' <a class="small_link_underline" href="artists_listings.php?s=' . (($display*($i - 1))) . '&np=' . $num_pages . '">'.$i.'</a> ';
} else {
echo $i.'';
}
echo'</td>';
}
// It it's not the last page, make a next button.
if ($current_page != $num_pages) {
echo '<td align="right"><a href="artists_listings.php?s=' . ($start + $display) . '&np=' . $num_pages . '"><img src="images/arrow_right.jpg" width="28" height="34" border="0"></a> </td></tr></table>';
}
echo '</td></tr></table><br /><br>';
} // End of links section.
$craft_query = 'select * from craft order by title';
$craft_result = mysql_query($craft_query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
while ($craft = mysql_fetch_array($craft_result)) {
$artists_query = "select * from artists where _craftId = '".$craft['craftId']."' order by name";
$artists_result = mysql_query($artists_query);
print'<h1>'.$craft['title'].'</h1>';
print'<table>';
if (mysql_num_rows($artists_result)) {
while ($artists = mysql_fetch_array($artists_result)) {
echo ''.$artists['name'].'<br>';
}
}
}
} else { // If there are no registered artists.
echo '<strong>There are currently no artists listings.</strong>';
}
mysql_close(); // Close the database connection.
include_once ('includes/footer.html'); // Require the HTML footer.
?>