Displaying a title only once
Posted: Thu Jul 13, 2006 4:47 am
Hi
I really hope someone can help but I'm trying to display data from my database in order of the particular craft a person is associated with. I can display all the necessary data in the database but I only want to display the craft once. So if there are two people who come under the craft 'Crafts' I only want to display the heading once and then feature both artits details underneath that heading. If I manually put in the heading it displays it even when you on the next page where there are no artists for that craft. This is the code I have for the page.
Thank you in advance I hope I've made sense in my description of the problem
I really hope someone can help but I'm trying to display data from my database in order of the particular craft a person is associated with. I can display all the necessary data in the database but I only want to display the craft once. So if there are two people who come under the craft 'Crafts' I only want to display the heading once and then feature both artits details underneath that heading. If I manually put in the heading it displays it even when you on the next page where there are no artists for that craft. This is the code I have for the page.
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.
$display = 4;
// Determine how many pages there are.
if (isset($_GET['np'])) { // Already been determined.
$num_pages = $_GET['np'];
} else { // Need to determine.
$query = "SELECT craft, name, description, address, tel, mobile, email, website FROM artists ORDER by craft 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 craft 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.
// Table header.
echo '<table align="left" cellspacing="0" cellpadding="0">';
// Fetch and print all the records
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr><td align="left" class="small"><strong>',stripslashes($row['craft']), '</strong><br><br></td></tr></tr><tr><td align="left" class="small"><strong>',$row['name'],'</strong></td></tr><tr><td align="left" class="small">',$row['description'],'</td></tr>';
if ($row['address']) {
echo '<tr><td align="left" class="small">',$row['address'],'</td></tr>';
}
if ($row['tel']) {
echo '<tr><td align="left" class="small">T: ',$row['tel'],'</td></tr>';
}
if ($row['mobile']) {
echo '<tr><td align="left" class="small">M: ',$row['mobile'],'</td></tr>';
}
if ($row['email']) {
echo '<tr><td align="left" class="small">E: <a href="mailto:',$row['email'],'" class="small_link">',$row['email'],'</a></td></tr>';
}
if ($row['website']) {
echo'<tr><td align="left" class="small">W: <a href="http://',$row['website'],'" class="small_link" target="blank">',$row['website'],'</a></td></tr>';
}
echo'<tr><td><br></td></tr>';
}
echo '</table>'; // Close the table
mysql_free_result ($result); // Free up the resources.
} 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.
?>