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! -
// Get start date and format properly for query string
-
$v_startdate = $_POST['sdate'];
-
$x_startdate = "'" . $v_startdate . "'" ;
-
-
// Get end date and format properly for query string
-
$v_enddate = $_POST['edate'];
-
$x_enddate = "'" . $v_enddate . "'" ;
-
-
-
-
// make connection to database
-
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
-
-
mysql_select_db($dbName) or die( "Unable to select database $dbName");
-
-
// 1st part - If the reservation is greater than or equal to the start date but ends before current date
-
// 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
-
$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
-
FROM reservations rv, resources rs, reservation_users ru, login li
-
WHERE rs.machid = rv.machid
-
AND ru.resid = rv.resid
-
AND li.memberid = ru.memberid
-
AND from_unixtime( rv.end_date ) <= CURRENT_DATE()
-
AND from_unixtime(rv.start_date) >= $x_startdate
-
UNION
-
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
-
FROM reservations rv, resources rs, reservation_users ru, login li
-
WHERE rs.machid = rv.machid
-
AND ru.resid = rv.resid
-
AND li.memberid = ru.memberid
-
AND from_unixtime( rv.end_date ) > CURRENT_DATE()
-
AND from_unixtime( rv.start_date ) < CURRENT_DATE()
-
AND from_unixtime(rv.start_date) >= $x_startdate
-
ORDER BY 4";
-
-
-
$result = mysql_query($query);
-
-
// Determine the number of reservations
-
$number = mysql_numrows($result);
-
-
// print the records
-
print "<h3><font face=Arial>There are $number records between $v_startdate and $v_enddate:</h3>
-
<table cellpadding=5>
-
<tr bgcolor=black>
-
<td><font color=white><b>Name</b></font></td>
-
<td><font color=white><b>Equipment</b></font></td>
-
<td><font color=white><b>Project</b></font></td>
-
<td><font color=white><b>Days_Out</b></font></td>
-
<td><font color=white><b>ID_Cost</b></td></font></tr>";
-
-
for ($i=0; $i<$number; $i++) {
-
$Name = mysql_result($result,$i,"Name");
-
$Last_Name = mysql_result($result,$i,"Last_Name");
-
$Equipment = mysql_result($result,$i,"Equipment");
-
$Project = mysql_result($result,$i,"Project");
-
$Days_Out = mysql_result($result,$i,"Days_Out");
-
$ID_Cost = mysql_result($result,$i,"ID_Cost");
-
// print "$a $b $c $d $e $f $g<br>";
-
-
if ($i%2 == 0) {
-
print "<tr bgcolor=lightgrey>";
-
} else {
-
print "<tr>";
-
}
-
print "<td>$Name $Last_Name</td>
-
<td>$Equipment</td>
-
<td>$Project</td>
-
<td align = center>$Days_Out</td>
-
<td>$ID_Cost</td></tr>";
-
}
-
print "</table>";
-
-
//print " $query " ;
-
-
-
// $timestampRightNow = time();
-
// print "$timestampRightNow";
-
print $CURRENT_DATE;
-
-
// Close the database connection
-
mysql_close();
-
?>
-
-
<p>
-
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.
Thanks, I got it working :o)
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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
...
| |
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...
|
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. ...
|
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
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |