|
|
Subject:
For joseleon-ga only
Category: Computers > Programming Asked by: belac-ga List Price: $10.00 |
Posted:
30 Dec 2003 13:18 PST
Expires: 29 Jan 2004 13:18 PST Question ID: 291564 |
Hello Jose, I am helping another friend with a keyword application and need to know how to do the following: The form is setup to allow a keyword to be entered but we need to check whether or not the user already submitted the keyword before allowing it to be entered into the database. I am assuming we have to put the "keyword_count" query in a list to compare it to or something? Here is the code: <!---get the users keywords-------------------------------------> <cfquery name="keyword_count" datasource="#ds#"> SELECT * FROM MasKeywords AS MK INNER JOIN MasProducts AS MP ON MP.ProductID = MK.ProductID WHERE MP.ProductID = '#form.PID#' AND MD.UserID = #session.UserID# AND MK.KeyActive = 1; </cfquery> <cfif #IsDefined("form.keyword")#> <!---strip illegal character and lowercase keyword before submitting--> <cfset TrimKeyword = '#trim('#form.Keyword#')#'> <cfset StripKeyword = "#replace(variables.TrimKeyword,Chr(39),"", 'all')#"> <cfset LowerCaseKeyword = "#lcase(StripKeyword)#"> </cfif> <!---check to see if keyword already exists----> <cfif #IsDefined("form.keyword")# AND "#LowerCaseKeyword#" IS NOT "??????"> <!---if passed, then create new keyword------------------------------------------------------> <cfquery name="create_keyword" datasource="#ds#" maxrows="1"> INSERT INTO MasKeywords ( ProductID, Keyword ) VALUES ( '#form.PID#', '#LowerCaseKeyword#' ); </cfquery> </cfif> | |
| |
| |
|
|
Subject:
Re: For joseleon-ga only
Answered By: joseleon-ga on 04 Jan 2004 07:20 PST Rated: |
Hello, belac: I cannot fully test this answer because I don't have all your table structures, but in any case, don't hesitate to request for any clarification until you get it working. What you have to do it's to "search" for the keywords the user wants to insert and then, check if the query has returned any results: <cfif #IsDefined("form.keyword")#> <!---strip illegal character and lowercase keyword before submitting--> <cfset TrimKeyword = '#trim('#form.Keyword#')#'> <cfset StripKeyword = "#replace(variables.TrimKeyword,Chr(39),"", 'all')#"> <cfset LowerCaseKeyword = "#lcase(StripKeyword)#"> </cfif> <!---get the users keywords-------------------------------------> <cfquery name="keyword_count" datasource="#ds#"> SELECT * FROM MasKeywords AS MK INNER JOIN MasProducts AS MP ON MP.ProductID = MK.ProductID WHERE MP.ProductID = '#form.PID#' AND MK.keywords = '#LowerCaseKeyword#' AND MD.UserID = #session.UserID# AND MK.KeyActive = 1; </cfquery> <!---check to see if keyword already exists----> <cfif #IsDefined("form.keyword")# AND "#LowerCaseKeyword#" AND "#keyword_count.Recordcount# EQ 0"> <!---if passed, then create new keyword------------------------------------------------------> <cfquery name="create_keyword" datasource="#ds#" maxrows="1"> INSERT INTO MasKeywords ( ProductID, Keyword ) VALUES ( '#form.PID#', '#LowerCaseKeyword#' ); </cfquery> </cfif> That is, this is a three step process: 1. Strip any strange character from the keyword and make it lowercase 2. Perform a query to check if the keyword is in the database 3. Check if that query returned any results, and insert the new record if the keyword don't exists Don't copy and paste this code as is, be aware of the query, because there is a line you may need to change: AND MK.keywords = '#LowerCaseKeyword#' I assume that there is a field on the MasKeywords database, called keywords, change it to fit your table structure. Please, don't hesitate to request for any clarification. Regards. | |
| |
| |
| |
|
belac-ga rated this answer: |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |