Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database search question

Status
Not open for further replies.

jarla

Programmer
Jan 2, 2001
34
FI
Hi again! I need some help with this simple problem:
I have search form with three textboxs. When the user put words to those boxes and push the submit -button, one cfm -page handles database connection which put those words to database and then launch the searchprogram. It works well with one word, but: How can I ask Coldfusion to take all of those words, search if any of them are already on my database and if some of them are not there, add them there? And if there is some of those words, add +1 to that word´s counter. As I told before, my system works well with one word but I don´t know how to check all words with "easy" way.
 
o.k. are you tryin' to make an expert system or what? anyway, you can do that by repeatin' the same process three times. i tried the followin' code:



<cfif isdefined(&quot;FrmSend&quot;)>

<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Select * From Words
Where Word = '#Form.Word1#'
</cfquery>

<cfif Q.recordcount EQ 0>
<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Insert Into Words (Word, WordCount)
Values ('#Form.Word1#', 1)
</cfquery>
<cfelse>
<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Update Words
Set WordCount = WordCount + 1
Where '#LCase(Form.Word1)#' = LCase(Word)
</cfquery>
</cfif>

<!--- repeat the same for the other 2 fields as the followin'--->

<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Select * From Words
Where Word = '#Form.Word2#'
</cfquery>

<cfif Q.recordcount EQ 0>
<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Insert Into Words (Word, WordCount)
Values ('#Form.Word2#', 1)
</cfquery>
<cfelse>
<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Update Words
Set WordCount = WordCount + 1
Where '#LCase(Form.Word2)#' = LCase(Word)
</cfquery>
</cfif>

<!--- for field 3 (Word3) --->

<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Select * From Words
Where Word = '#Form.Word3#'
</cfquery>

<cfif Q.recordcount EQ 0>
<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Insert Into Words (Word, WordCount)
Values ('#Form.Word3#', 1)
</cfquery>
<cfelse>
<cfquery datasource=&quot;words&quot; name=&quot;Q&quot;>
Update Words
Set WordCount = WordCount + 1
Where '#LCase(Form.Word3)#' = LCase(Word)
</cfquery>
</cfif>

<cfelse>

<form action=&quot;Words.cfm&quot; method=&quot;post&quot;>
Word1: <input type=&quot;text&quot; name=&quot;Word1&quot;><br>
Word2: <input type=&quot;text&quot; name=&quot;Word2&quot;><br>
Word3: <input type=&quot;text&quot; name=&quot;Word3&quot;><br>
<input type=&quot;submit&quot; name=&quot;FrmSend&quot; value=&quot;Send&quot;>
</form>

</cfif>


I hope this will help u. <Always there's a solution>
</Always there's a solution>
 
Thanks! That works! Somebody said that &quot;if it is not broken, don´t fix it&quot;, but I wonder is there any way to do that with shorter code...But the most important thing is that it works now:)
 
o.k. jarla. i gave u the idea that i know. check cfhub's idea too, maybe it's better :)

thanx for help, cfhub ;) <Always there's a solution>
</Always there's a solution>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top