When you build search interfaces, keep in mind that there won't always be a record returned. If there is at least one record returned from a query, you will usually format that data using an HTML table. But to make sure that a search has retrieved records, you will need to test if any records have been returned using the recordcount variable in a conditional logic expression in order to display search results appropriately to users.
For example, this code would be placed after the query to:
<CFIF GetEmployees.RecordCount IS "0">
No records match your search criteria. <br>
Please click<b> Search </b>on the toolbar and try again.
<CFELSE>
<TABLE CELLSPACING="2" CELLPADDING="2" WIDTH="95%">
<TR>
<TH ALIGN="LEFT">First Name</TH>
<TH ALIGN="LEFT">Last Name</TH>
<TH ALIGN="LEFT">Department</TH>
<TH ALIGN="LEFT">Start Date</TH>
<TH ALIGN="LEFT">Salary</TH>
<TH ALIGN="LEFT">Status</TH>
</TR>
<CFOUTPUT QUERY="GetEmployees">
<TR>
<TD>#GetEmployees.FirstName#</TD>
<TD>#GetEmployees.LastName#</TD>
<TD>#GetEmployees.Department_Name#</TD>
<TD>#DateFormat(GetEmployees.StartDate)#</TD>
<TD>#DollarFormat(GetEmployees.Salary)#</TD>
<TD><CFIF Contract IS "Yes">Contract
<CFELSE>Permanent</CFIF></TD>
</TR>
</CFOUTPUT>
</TABLE>
| To return search results to users: |
SearchAction.cfm in HomeSite.<H4>Employee Search Results</H4>
<CFIF GetEmployees.RecordCount IS "0"> No records match your search criteria. <BR> Please click searh button and try again.
<TABLE CELLSPACING="2" CELLPADDING="2" WIDTH="95%">
<CFOUTPUT QUERY="GetEmployees">
<TR>
<TD>#GetEmployees.FirstName#</TD>
<TD>#GetEmployees.LastName#</TD>
<TD>#GetEmployees.Department_Name#</TD>
<TD>#DateFormat(GetEmployees.StartDate)#</TD>
<TD>#DollarFormat(GetEmployees.Salary)#</TD>
<TD><CFIF Contract IS "Yes">
Contract
<CFELSE>Permanent</CFIF></TD>
</TR>
</CFOUTPUT>
</TABLE>
<TR>
<TH ALIGN="LEFT">First Name</TH>
<TH ALIGN="LEFT">Last Name</TH>
<TH ALIGN="LEFT">Department</TH>
<TH ALIGN="LEFT">Start Date</TH>
<TH ALIGN="LEFT">Salary</TH>
<TH ALIGN="LEFT">Status</TH>
</TR>
</CFIF>
EmpList.cfm in a browser. The SELECT statement on SearchAction.cfm returns different results based on
the criteria that you submit.
Click here to run a search from SearchForm.cfm.
Click here to see SearchAction.cfm's code.
Before beginning the next chapter, move on to the summary to review development considerations.