$title = 'Salem Local Businesses and Services';
$email_subject = 'Salem: Add local service or business';
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/before.php';
echo '';
echo '
'.$title.'
';
echo 'Not all services are available in all areas. Call each service to verify availability at your address.
'.PHP_EOL;
echo ' Jump to: ';
$query = '
SELECT *
FROM salemtsh_categories
ORDER BY cat
';
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($result)) {
echo '
'.$row['cat'].' | ';
}
echo '
';
$query = '
SELECT salemtsh_businesses.*, salemtsh_categories.cat as cat_name, salemtsh_categories.id as cat_id, salemtsh_businesses.id as bus_id
FROM salemtsh_businesses
LEFT JOIN salemtsh_categories ON salemtsh_businesses.category = salemtsh_categories.id
WHERE category>0 and in_salem = 1
ORDER BY cat_name, title
';
$result = mysqli_query($conn, $query);
if (!$result) {
die("Error in SQL query: " . mysqli_error($conn));
}
$previousCat = null;
while ($row = mysqli_fetch_array($result)) {
$currentCat = $row['category'];
// Check if the current category is different from the previous category
if ($currentCat != $previousCat) {
// Close the previous category group if not the first iteration
if ($previousCat !== null) {
echo ''.PHP_EOL; // Close the previous category group
}
// Start a new category group
echo ''.PHP_EOL;
echo '
';
echo '
'.$row['cat_name'].'
'.PHP_EOL; // Display category name
}
echo '
';
if ($validated == 1) {
echo ' ';
}
if (!empty($row['link'])) {
echo ''.$row['title'].'';
} else {
echo $row['title'];
}
if (!empty($row['tel'])) {
if (strlen($row['tel']) == 10) {
$formatted_tel = '('.substr($row['tel'], 0, 3).') '.substr($row['tel'], 3, 3).'-'.substr($row['tel'], 6);
} else {
// Handle the case where $row['tel'] is not 10 digits
$formatted_tel = '';
}
echo ' - '.$formatted_tel.'';
}
if (!empty($row['note'])) {
echo ' - '.$row['note'];
}
echo ''.PHP_EOL;
$previousCat = $currentCat; // Update the previousCat for the next iteration
}
echo '
Are we missing a business or service in
Salem Township? Contact '.$admin.'! Be sure to include a date or at least a year, complete details and an image if you have it.
';
// Close the last category group
if ($previousCat !== null) {
echo '
'.PHP_EOL;
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/after.php';
?>