Database Dates (between ranges)
1) The form that inserts the date into the database
<input type="text"
name="uName">
<!-- HERE WE FORMAT THE DATE PROPERLY TO INSERT INTO DATABASE USING A HIDDEN FIELD-->
<input type="hidden"
name="testDate"
value="#DateFormat(now(), 'mm/dd/yyyy')#">
<input type="submit"
value="Submit Your Answers">
---------------------------------------
2) The SQL that inserts the data:
<CFINSERT DATASOURCE="mywebsite"
TABLENAME="tblTestResults"
FORMFIELDS="uName, testDate">
---------------------------------------
3) The form to search date ranges:
The dates are prefilled with today's date to prompt the user for the correct date syntax. When the user clicks or tabs into the text box the dates dissappear. SYNTAX EX: 12/07/1941
<p>Start Date: <input
type="text"
name="startDate" value="#DateFormat(Now(),
'mm/dd/yyyy')#" onfocus="this.value=''"
style="background-color:##f2f2f2;"><br>
End Date: <input type="text"
name="endDate"
value="#DateFormat(Now(),
'mm/dd/yyyy')#" onfocus="this.value=''"
style="background-color:##f2f2f2;">
---------------------------------------
4) The SQL that queries the dates between the prescribed ranges in the form:
<cfquery name="testresults"
datasource="mywebsite">
SELECT *
From tblTestResults
WHERE ((tblTestResults.testDate BETWEEN #CreateODBCDate(form.StartDate)# AND #CreateODBCDate(form.EndDate)#))
ORDER BY uName
</cfquery>
---------------------------------------
5) And displaying the results of the date range query:
<table cellpadding="1"
cellspacing="0"
width="100%"
border="1"
bordercolor="silver">
<tr>
<th>Member Name</th>
<th>Completed</th>
</tr>
<!-- IF THERE ARE NO RESULTS -->
<cfif #testresults.recordcount# is 0>
<tr>
<td colspan="2"
align="center">No records found in that date range</td>
</tr>
</cfif>
<!-- IF THERE ARE RESULTS THEN DISPLAY THEM -->
<cfoutput query="testresults">
<tr>
<td>#testresults.uName#</td>
<td>#DateFormat(testresults.testDate,
'mm/dd/yyyy')#</td>
</tr>
</cfoutput>
</table>
-
Aliasing Your SQL Statements
Many developers I have talked to are not aware of the ability to create an "alias" in an SQL statement, concatenate, and even add strings into your SQL statements. A little work up front in the SQL can cut out a lot of tedious coding in the tag.
Author: Jim Summer
Views: 15,947
Posted Date: Tuesday, December 10, 2002
-
Database Dates (between ranges)
This deals with database dates:
(1)inserting a properly formatted date into the database, and then
(2)pulling a query from the database between a date range defined by 2 text boxes.
Author: Jim Summer
Views: 19,024
Posted Date: Monday, December 9, 2002
-
Navigation as an include file
Create an include file (custom tag) for your navigation to help make maintenance easier! This include file lights up the button depending on where the user is at in your website, and is XHTML 1.1 validated! If you need to edit your navigation, just do it in 1 place, the include file! Javascript included :)
Author: Jim Summer
Views: 54,928
Posted Date: Thursday, December 12, 2002
-
Recordset Paging in Cold Fusion
This will pull a predefined number of records from a database, allow the user to change the number of records to be shown, and write the "NEXT" or "BACK" (or both) buttons at the bottom of the page. Thus allowing the user to "surf" through the database.
See it in action at http://freecfm.com/t/tentonhead/ and click on the "CTCS" link when you get there.
The HTML for this page has changed a little since I first did this (so it validates as XHTML1.1) but the CFML remains as it is in this snippet.
Author: Jim Summer
Views: 28,787
Posted Date: Monday, December 9, 2002
-
Replacing "enter" key with "<br>" tag
This little piece of code will transform those pesky "enter" keys in a textarea into "
" tags so your users input is printed out properly in your html page.
Author: Jim Summer
Views: 19,113
Posted Date: Friday, December 13, 2002
-
Search Engine Bot Notifier
This code detects the most common user agents (web browsers) and notifies you via email if it is not a recognized user agent as defined in the code. Usually this will be a bot of some sort. Extrememly useful for tracking how often Google, Yahoo, etc visits your site. It will email you the bot and a reverse IP lookup url with the IP appended so you can verify if it is a "good bot" or a "bad (spam) bot" (then you can block that IP or stop processing of the page). Use this in your home page or as an include file throughout your site. Nothing fancy it should work on MX also although I have not tested it there.
Author: Jim Summer
Views: 14,430
Posted Date: Wednesday, April 14, 2004