PDA

View Full Version : coldfusion/sql server search form question



lunatic
June 23rd, 2004, 02:24 PM
Howdy all,

I am stumbling my way through learning coldfusion by building a project log for our group at work. I am stuck on building a search page. My search page seems really simple. I have one textbox that allows users to enter a job number, and then two text boxes that allow users to enter a word to search ALL the fields in the big table by. Between the two search fields are two radio buttons (and/or) so the user can specify keyword 1 AND/OR keyword 2.

I should mention now that the query and queryResults pages I am building are adopted from a set given me by an acquaintance (who actually got his to work but is unavailable to me at the moment).

The query page has the following code:


<html>
<head>
<title>Query the Project Log</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<div align="center">
<p><font size="4"><strong>Query the Project Log</strong></font><br>
(all fields optional)
</p>
</div>
<table align="center" cellpadding=10>
<form action="queryResults.cfm" method="post">
<tr><td width="79">Job Number:</td>
<td width="350" colspan="2"><input name="Job_Number" type="text" maxlength="10"></td></tr>
<tr><td>Query string:</td>
<td colspan="2"><input name="querystring1" type="text" size="50" maxlength="50"></td></tr>
<tr><td colspan="3" align="center">
<INPUT TYPE="radio" NAME="querytype" VALUE="and" checked>AND
<input type="radio" name="querytype" value="or">OR
</td></tr>
<tr><td>Query string:</td>
<td colspan="2"><input name="querystring2" type="text" size="50" maxlength="50"></td></tr>
<tr><td div align="center" colspan="2"><input type="submit" value="Search"></td></tr>
</form>
</table>
</body>
</html>


And the queryResults page has the following code:



<cfquery name="q_queryResults" datasource="PLOG">
SELECT *
FROM data_admin.Main_log
WHERE del_job = 0
AND 0=0

<CFIF #FORM.Job_Number# IS NOT "">
AND Job_Number LIKE (#FORM.Job_Number#)
</CFIF>

<CFIF #FORM.querystring1# IS NOT "">
AND ( upper(trim(Refuge_Literal)||' '||trim(Requestor)||' '||trim(Requestor_Office)||' '||trim(Project_Type)||' '||trim(Map_Type)||' '||trim(Rq_Description) ||' '||trim(Assigned_To)) LIKE upper('%#FORM.querystring1#%')
</CFIF>

<CFIF #FORM.querystring2# IS "" AND #FORM.querystring1# IS NOT "">
)
</CFIF>

<CFIF #FORM.querystring2# IS NOT "">
#FORM.querytype# upper(trim(Refuge_Literal)||' '||trim(Requestor)||' '||trim(Requestor_Office)||' '||trim(Project_Type)||' '||trim(Map_Type)||' '||trim(Rq_Description) ||' '||trim(Assigned_To)) LIKE upper('%#FORM.querystring2#%') )
</CFIF>

ORDER BY Date_Assigned DESC, Job_Number DESC

</cfquery>


and then a table to display the data.

But it's not working. If I put in a job number, or even a partial job number then I get the table to display but no data is returned (only the column headings show). If I put something into the text fields then I get an error message that says

[Macromedia][SQLServer JDBC Driver][SQLServer]'trim' is not a recognized function name.

Sorry to go on and on but I really need this working. Anyone have a clue what is wrong or maybe a better way to search all fields using more than one keyword?

any help GREATLY appreciated!

:hr:

Digitalosophy
June 23rd, 2004, 04:16 PM
well im no coldfusion expert, so id my advice is off then please excuse me.

your SQL statement doesn't look right to me.


SELECT *
FROM data_admin.Main_log
WHERE del_job = 0
AND 0=0


shouldn't you be selecting all data where del_job is equal to the textfield?

lunatic
June 23rd, 2004, 05:32 PM
I actually was just coming in to delete this thread as I figured it out. As is true in most cases I deleted everything and started over from scratch. Works great now. :beam:

del_job is a checkbox so it has a boolean value in the database

thanks for checking it out though! :hr:

DariusMonsef
June 25th, 2004, 01:02 AM
Luni, IM if you have any other CF questions.

lunatic
June 28th, 2004, 11:24 PM
Hey EthanM just saw this post today (I've been out rafting the John Day River the last 4 days . . . mmmmm wonderful, am now very burnt and hungover ;) ). Anyway, thanks so much! I will definitely get in touch with you if I have any more questions (and I'm sure I will!). I came across a few posts by you that looked like you knew CF when I was doing some searching. Thanks again. :pleased: