hyperlink that calls data from mysql
I'm trying to create a page with a hyperlinks that when clicked will display all the records in the table with a reminder date that is within the current week (Sun-Sat) however by defaul all reminders for the current day are showing. Thanks for your help!
// not sure how to create the link for 'Week'
<li><a href="/backend/followup/followup.php">Today</a></li> // default page
<li><a href="/backend/followup/followup.php?reminder=">Week</a></li>
Here is what I have so far and I'm not sure how to put this all together so that by default all reminders for today show up, but if hyperlink 'Week' is clicked only those results show up
$today = date('Y-m-d', strtotime('today'));
$week = date('Y-m-d', strtotime('last sunday'));
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder = '$today' ORDER BY contacttodo.reminder ASC";
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder BETWEEN '$week' AND '$week' + INTERVAL 6 DAY ORDER BY contacttodo.reminder ASC";
UPDATE- This is working (except for 'lastweek'):
if($_GET['reminder'] == 'lastweek') {
$lastweek = date('Y-m-d', strtotime('last sunday'));
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder BETWEEN '$lastweek' AND '$lastweek' - INTERVAL 6 DAY ORDER BY contacttodo.reminder ASC";
}
elseif
($_GET['reminder'] == 'thisweek') {
$thisweek = date('Y-m-d', strtotime('last sunday'));
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder BETWEEN '$thisweek' AND '$thisweek' + INTERVAL 6 DAY ORDER BY contacttodo.reminder ASC";
}
elseif
($_GET['reminder'] == 'nextweek') {
$nextweek = date('Y-m-d', strtotime('next sunday'));
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder BETWEEN '$nextweek' AND '$nextweek' + INTERVAL 6 DAY ORDER BY contacttodo.reminder ASC";
}
elseif
($_GET['reminder'] == 'thismonth') {
$thismonth = date('Y-m-d');
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND YEAR(reminder) = YEAR(CURDATE()) AND MONTH(reminder) = MONTH(CURDATE())ORDER BY contacttodo.reminder ASC";
}
elseif
($_GET['reminder'] == 'thisquarter') {
$thisquarter = date('Y-m-d');
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND YEAR(reminder) = YEAR(CURDATE()) AND QUARTER(reminder) = QUARTER(CURDATE())ORDER BY contacttodo.reminder ASC";
}
elseif
($_GET['reminder'] == 'thisyear') {
$thisyear = date('Y-m-d');
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND YEAR(reminder) = YEAR(CURDATE()) ORDER BY contacttodo.reminder ASC";
}
else {
$today = date('Y-m-d', strtotime('today'));
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder = '$today' 开发者_JAVA技巧ORDER BY contacttodo.reminder ASC";
From what I understand from your question, this should help you get going.
Change your link to
<a href="/backend/followup/followup.php?reminder=week">Week</a>
and code to
if($_GET['reminder'] == 'week') {
$week = date('Y-m-d', strtotime('last sunday'));
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder BETWEEN '$week' AND '$week' + INTERVAL 6 DAY ORDER BY contacttodo.reminder ASC";
} else {
$today = date('Y-m-d', strtotime('today'));
$query = "SELECT * FROM contacttodo,contacts WHERE contacttodo.contacts_id = contacts.ID AND contacttodo.reminder = '$today' ORDER BY contacttodo.reminder ASC";
}
/* Code to execute query and print results */
精彩评论