Forum Moderators: coopster
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org]; xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Multidimensional Arrays</title>
<style type="text/css" title="text/css" media="all">
body {font-size: xx-medium;}
</style>
</head>
<form action="test_austin.php"
method="post">
<input type="checkbox" name="interests[]" value="Fireside" <?php echo (isset($_POST['interests']) && in_array('Fireside',$_POST['interests'])) ? 'checked':''; ?> />Fireside
<input type="checkbox" name="interests[]" value="Dance" <?php echo (isset($_POST['interests']) && in_array('Dance',$_POST['interests'])) ? 'checked':''; ?> />Dance
<input type="submit" name="submit" value="Submit" />
</form>
<body>
<?php
$a[0] = $_POST['interests'][0];
$a[1] = $_POST['interests'][1];
$dbc = @mysqli_connect ('localhost', 'someuser', 'somepass', 'test_austin')
or die ('could not connect to MySQL: ' . mysqli_connect_error() );
// ########################################################Determine the sort...
//$a[0] = "Fireside";
//$a[1] = "Dance";
// Determine the sorting order:
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'dm';
$link1 = "{$_SERVER['PHP_SELF']}?sort=ad";
$link2 = "{$_SERVER['PHP_SELF']}?sort=ct";
$link3 = "{$_SERVER['PHP_SELF']}?sort=dm";
switch ($sort) {
case 'ad':
$order_by = 'addr ASC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=ad";
break;
case 'ct':
$order_by = 'city ASC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=ct";
break;
case 'dm':
$order_by = 'daate ASC';
$link3 = "{$_SERVER['PHP_SELF']}?sort=dm";
break;
default:
$order_by = 'daate ASC';
$link3 = "{$_SERVER['PHP_SELF']}?sort=dm";
break;
}
// Make the query:
$q = "SELECT CONCAT(activity, ', ', sponsor) as name, address as addr, city as city, month as month, week as week, day as day, daate as daate, count as count FROM austintable WHERE (activity = '$a[0]' OR activity = '$a[1]') ORDER BY $order_by " ;
$r = mysqli_query ($dbc, $q);
//echo "datebase and query set";
if ($r) { // If it ran OK, display the records.
//############# Print Table header.
echo '<table align="left" cellspacing="0" cellpadding="3" width="70%"><tr><td align="left"><b>Sponsor</b></td><td align="left"><b><a href="'.$link1.'">Address</a></b></td><td align="left"><b><a href="'.$link2.'">City</a></b></td><td align="left"><b>W-M-D</b></td><td align="left"><b><a href="'.$link3.'">Event (Y-M-D)</a></b></td></tr>';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$critera1 = $row['week'] . '-' . $row['month'] . '-' . $row['day'];
$yr = date('Y');
$monnth = date('m') + $row['month'] - 1 ;
$monnth1 = date("m", mktime(0, 0, 0, $monnth, 1, $yr));
$dayy1 = date("w", mktime(0, 0, 0, $monnth, 1, $yr));
// the following is the logic that creates the event day
if ($row['day'] >= $dayy1 && $row['month'] == 1) { $today5 = $row['week'] * 7 + $row['day'] + 1 - $dayy1; // if DOE falls after the day associated with 1st DOM do this
} else {$today5 = $row['week'] * 7 + 1 + $row['day'] + (7 - $dayy1); // else if DOE falls before day associated with 1st DOM do this
}
$today5a = date("d", mktime(0, 0, 0, $monnth, $today5, $yr));
$q1 = "UPDATE austintable SET daate = CONCAT($yr, ', ', '$monnth1', ', ', '$today5a') WHERE daate = 0 limit 1";
$r1 = mysqli_query ($dbc, $q1);
//############# Print table fields if today's date is < event date
//if (date('d') <= $today5 ¦¦ $row['month'] > 1) {
echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['addr'] . '</td><td align="left">' . $row['city'] . '</td><td align="left">' . $critera1 . '</td><td align="left">' . $row['daate'] . '</td></tr>';
//}//########### logic that prints only current event dates #######################------
}
echo '</table>'; // Close the table.
mysqli_free_result ($r); // Free up the resources.
} else { // If it did not run OK.
echo '<p class="error">The current users could not be retrieved. We apologize for any inconvenience.</p>';
// Debugging message:
echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
} // End of if ($r) IF.
mysqli_close($dbc); // Close the database connection.
?>