473,507 Members | 12,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A little help with POST and DATE fields

2 New Member
Hi,
I have a php form that I want to use to pass a user specified "start date" and "end date" to a mysql database to retrieve reservations.

I want the number of days up to and including the "end date" to be displayed for both of these scenarios:
1) The item is still on loan as of the "end date"
2) The item has already been returned as of the "end date"

Right now I have it working by specifying a "start date", but the "end date" is actually set to the "current date". This would be fine, but I might need to go back and select all reservations in July, which would mean a whole lot of extra days being tallied up to today.

So, here is my code. The problem I am having is that the user input is a string, which I must convert before subtracting it from the start date. How do I do this?

Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1. // Get start date and format properly for query string
  2. $v_startdate = $_POST['sdate'];
  3. $x_startdate = "'" . $v_startdate . "'" ;
  4.  
  5. // Get end date and format properly for query string
  6. $v_enddate = $_POST['edate'];
  7. $x_enddate = "'" . $v_enddate . "'" ;
  8.  
  9.  
  10.  
  11. // make connection to database
  12. mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
  13.  
  14. mysql_select_db($dbName) or die( "Unable to select database $dbName");
  15.  
  16. // 1st part - If the reservation is greater than or equal to the start date but ends before current date
  17. // 2nd part - If the reservation is greater than or equal to the start date but ends after current date, I want to see up to current date
  18. $query = "SELECT li.fname Name, li.lname Last_Name, rs.name Equipment, rv.summary Project, (TO_DAYS( from_unixtime( rv.end_date ) ) - TO_DAYS( from_unixtime( rv.start_date ) )) + 1 Days_Out , rs.notes ID_Cost
  19. FROM reservations rv, resources rs, reservation_users ru, login li
  20. WHERE rs.machid = rv.machid
  21. AND ru.resid = rv.resid
  22. AND li.memberid = ru.memberid
  23. AND from_unixtime( rv.end_date ) <= CURRENT_DATE() 
  24. AND from_unixtime(rv.start_date) >= $x_startdate
  25. UNION
  26. SELECT li.fname Name, li.lname Last_Name, rs.name Equipment, rv.summary Project, (TO_DAYS( CURRENT_DATE( ) ) - TO_DAYS( from_unixtime( rv.start_date ))) + 1 Days_Out,  rs.notes ID_Cost
  27. FROM reservations rv, resources rs, reservation_users ru, login li
  28. WHERE rs.machid = rv.machid
  29. AND ru.resid = rv.resid
  30. AND li.memberid = ru.memberid
  31. AND from_unixtime( rv.end_date ) > CURRENT_DATE() 
  32. AND from_unixtime( rv.start_date ) < CURRENT_DATE()
  33. AND from_unixtime(rv.start_date) >= $x_startdate
  34. ORDER BY 4";
  35.  
  36.  
  37. $result = mysql_query($query);
  38.  
  39. // Determine the number of reservations
  40. $number = mysql_numrows($result);
  41.  
  42. // print the records
  43. print "<h3><font face=Arial>There are $number records between $v_startdate and $v_enddate:</h3>
  44.     <table cellpadding=5>
  45.     <tr bgcolor=black>
  46.       <td><font color=white><b>Name</b></font></td>
  47.       <td><font color=white><b>Equipment</b></font></td>
  48.       <td><font color=white><b>Project</b></font></td>
  49.       <td><font color=white><b>Days_Out</b></font></td>
  50.       <td><font color=white><b>ID_Cost</b></td></font></tr>";
  51.  
  52. for ($i=0; $i<$number; $i++) {
  53.      $Name = mysql_result($result,$i,"Name");
  54.      $Last_Name = mysql_result($result,$i,"Last_Name");
  55.      $Equipment = mysql_result($result,$i,"Equipment");
  56.      $Project = mysql_result($result,$i,"Project");
  57.      $Days_Out = mysql_result($result,$i,"Days_Out");
  58.      $ID_Cost = mysql_result($result,$i,"ID_Cost");   
  59. //     print "$a $b $c $d $e $f $g<br>";
  60.  
  61. if ($i%2 == 0) {
  62.         print "<tr bgcolor=lightgrey>";
  63.         } else {
  64.         print "<tr>";
  65.         }
  66.     print "<td>$Name $Last_Name</td>
  67.     <td>$Equipment</td>
  68.     <td>$Project</td>
  69.     <td align = center>$Days_Out</td>
  70.     <td>$ID_Cost</td></tr>"; 
  71. }
  72. print "</table>";
  73.  
  74. //print " $query " ;
  75.  
  76.  
  77. // $timestampRightNow = time();
  78. // print "$timestampRightNow";
  79. print $CURRENT_DATE;
  80.  
  81. // Close the database connection
  82. mysql_close();
  83. ?>
  84.  
  85. <p>
  86.  
Oct 13 '07 #1
3 1293
ak1dnar
1,584 Recognized Expert Top Contributor
You can use checkdate() function for validate the date format.
Tip: Better to set up list menus to select dd mm yyyy, instead of a text input box.
Oct 13 '07 #2
shmoopie
2 New Member
Thanks, I got it working :o)
Oct 14 '07 #3
ak1dnar
1,584 Recognized Expert Top Contributor
Thanks, I got it working :o)
Glad to here you got it working. And If you can post the answer here, It will help for the others, who is having the same problem. Thanks.
Oct 15 '07 #4

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

Similar topics

10
2233
by: Dan Weeb | last post by:
Hi Guys, I really am a novice and found a script on webmonkey. Basically all I want to do is to add records to my database. In my database I have a table called research_main with the fields...
3
3699
by: Ricardo Sanchez | last post by:
Hello, I'm trying to upload images to http://imageshac.us via a Python script. I have looked at the POST request with HTTPLiveHeaders Firefox extension when I upload an image, but I can't...
16
3037
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a...
9
3934
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
32
12472
by: robert d via AccessMonster.com | last post by:
I'm looking at converting DAO to ADO in my app. All of my DAO connections are of the following structure: Dim wsName As DAO.Workspace Dim dbName As DAO.Database Dim rsName As DAO.Recordset ...
3
3321
by: mcmahonb | last post by:
Hey people... I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my...
13
1693
by: Jack B | last post by:
I'm using Access 2002 to create a database for a small opera company that my wife is involved in, and I'm more than a bit rusty because I haven't created a new Access database since about 1999. ...
3
2314
by: Ethan Furman | last post by:
len wrote: I've never had the (mis?)fortune to work with COBOL -- what are the files like? Fixed format, or something like a dBase III style? I
2
2996
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.