473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using date link from a calender to query table

osward
38
Hi everyone,

Background
1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >= current date. Otherwise, user have to waste time to page up the pages to find the current date

2. I got a script of simple calendar from the web that use mktime() to create links on the calendar

Task
I need to let user view data earlier than today, I have to do either one of the things
a) I am able to show all the database records and when user request the table, I can show them the right page. ie. I am not showing the 1st page of the table but rather the page consits of today's date.

b) I make use of the simple calendar date link as a navigation mechanism and display the rows of data of the request date and later. Personally I think this is cool than (a) and more efficient to browse around the table.
The query to the table is as follows:
[PHP]$result = $db->sql_query("SELECT * FROM ".$prefix."_event_cat WHERE date >= CURDATE() ORDER by $sort_order LIMIT $from, $max_results") or die("Error: " . mysql_error());
if($db->sql_numrows($result) == 0){
echo(""._NODATA."");
}[/PHP]and the links of the calendar is

[PHP]// Build Previous and Next Links
$previous_link = "<a href=\"/modules.php?name=event&date=";
if($month == 1){
$previous_link .= mktime(0,0,0,12,$day,($year -1));
} else {
$previous_link .= mktime(0,0,0,($month -1),$day,$year);
}
$previous_link .= "\"><< "._PREVMON."</a>";

$next_link = "<a href=\"/modules.php?name=event&date=";
if($month == 12){
$next_link .= mktime(0,0,0,1,$day,($year + 1));
} else {
$next_link .= mktime(0,0,0,($month +1),$day,$year);
}
$next_link .= "\">"._NEXTMON." >></a>";

// Now we break each key of the array
// into a week and create a new table row for each
// week with the days of that week in the table data

$i = 0;
foreach($weeks AS $week){
echo "<tr>\n";
foreach($week as $d){
if($i < $offset_count){
$day_link = "<a href=\"modules.php?name=event&date=".mktime(0,0,0, $month -1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"modules.php?name=event&date=".mktime(0,0,0, $month,$d,$year)."\">$d</a>";
if($date == mktime(0,0,0,$month,$d,$year)){
echo "<td class=\"today\">$d</td>\n";
} else {
echo "<td class=\"days\">$day_link</td>\n";
}
} elseif(($outset > 0)) {
if(($i >= ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"modules.php?name=event&date=".mktime(0,0,0, $month +1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
}
$i++;
} [/PHP]
How am I going to send the date link to the query, I know I need to convert the date by d= date("Y-m-d", $date) because my date field in the table is "Y-m-d" format to do the comparison. I just couldn't figure out how I am going to put into the query

Please help me in either way, doing (a) or (b)

Thanks in advance
Nov 5 '07 #1
1 2593
pbmods
5,821 Expert 4TB
Heya, Osward.

I'd see something like this:
Expand|Select|Wrap|Line Numbers
  1. $__targetDate =
  2.     strtotime
  3.     (
  4.         $_POST['year']
  5.         . '-'
  6.         . $_POST['month']
  7.         . '-'
  8.         . $_POST['day']
  9.     );
  10. if( $__targetDate )
  11. {
  12.     $__minDate = "'" . date('Y-m-d', $__targetDate) . "'";
  13. }
  14. else
  15. {
  16.     $__minDate = 'CURDATE()';
  17. }
  18.  
  19. $result =
  20.     $db->sql_query
  21.     ("
  22. SELECT
  23.         *
  24.     FROM
  25.         `{$prefix}_event_cat`
  26.     WHERE
  27.         `date` >= {$__minDate}
  28.     ORDER BY
  29.         `{$sort_order}`
  30.     LIMIT {$from}, {$max_results}"
  31.     )
  32.         or exit('Error: ' . mysql_error());
  33.  
Nov 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
5
by: Alicia | last post by:
Yes, but will that skip a week and group by the date for me? I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date ...
4
by: Ali | last post by:
i am using visual studio 2005 and I am trying to create a popup calender so when a user click on a image on the main form, a calender will then popup, the user will select a date and the date will...
24
by: bloukopkoggelmander | last post by:
Right here is my problem. I have various tables ie. NL Clients(ClientID,ClientFirst,ClientLast, Address,Postcode etc.) NL Treatments(TreatmentID,Treatment) NL Costs(CostID,Cost) NL Client...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
1
by: vp.softverm | last post by:
hi all . Am facing problem with the date picker. when i click on date picker in a popup window. the date table is opened in the middle of the pop up window. and it is unable to scroll with...
8
by: Greg (codepug | last post by:
For lack of the proper expression, how do I excite a control to cause events to trigger. I have a date control and am using a calender form button to fill the text box with the date. The text box...
1
by: swethak | last post by:
hi, i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily calendar.Any body plz suggest that what modifications i...
21
Vkas
by: Vkas | last post by:
i had created my own web calender control!!!! it consist 1} text box (it display's the selected date) 2} button (it hide and show the calender control) 3} calender control (use for the selection...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.