By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,117 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

Multiple Search Parameters in one Form

P: 3
Hello,

I've been working on trying to figure out how to script something where if a user enters more then one search term in the same fieldbox, it would query both of them and output it to a cf page.

My scripting/issue is very similiar to an early thread by an individual here
http://bytes.com/forum/thread655581.html

Basically in my case....these are not words I am entering...I would be entering lets say 500-900 different email addresses into this one form -




then what it does is output them to view all of these email addresses with their phone numbers from the database on the search results page to a table ....now this only works if i enter one email address in the form it finds it fine...but when i enter more then one email addresses in the search form it doesn't find it....
Aug 1 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
If it's in that format, you can use it as a list, or use the IN keyword in your SQL statement.
Aug 1 '08 #2

P: 3
Sorry I'm a little ignorant when it comes to this...What exactly do you mean by that? Right now here is my coding on the search page where the user would input the search query:

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3.     <TITLE>Bad Emails / Phone Compiler v0.1</TITLE>
  4.  
  5. <script language="JavaScript" >
  6.  
  7.  
  8. function checkText(Item, Value)
  9. {
  10.  var next=Item.tabIndex;
  11.  for(i=1; i <  document.getElementById("searchForm101").length; i++)
  12.  {
  13.   if(i == next)
  14.   {
  15.    // leave textfield as is.
  16.   }
  17.   else
  18.   {
  19.    document.getElementById("searchForm101").elements[i].value  = ""; // Erase other fields
  20.   }
  21.  }
  22.  document.getElementById("searchForm101").elements[document.getElementById("searchForm101").length - 1].value  = "Search"; // Update the entry 
  23. }
  24.  
  25. </script>
  26.  
  27. <script language="JavaScript" > 
  28. function validate()
  29. {
  30.  var count=0;
  31.  for(i=1; i <  document.getElementById("searchForm101").length; i++)
  32.  {
  33.   if (document.getElementById("searchForm101").elements[i].value  == "")
  34.   {
  35.    count++;
  36.   }
  37.  }
  38.  if(count == (document.getElementById("searchForm101").length - 2) )
  39.  {
  40.   var newHTML = "<span style='color:#ff0000'>" + 'Please enter text.' + "</span>";
  41.   document.getElementById('ErrorMessage').innerHTML = newHTML;
  42.   return false;
  43.  }
  44.  else
  45.  {
  46.   return true;
  47.  }
  48. }    
  49. </script>
  50.  
  51. </HEAD>
  52.  
  53. <BODY bgcolor="ffffff">
  54. <CENTER>
  55. <TABLE cellpadding="0" cellspacing="0" border="0" width="300" bgcolor="dddddd">
  56.     <TR bgcolor="008800">
  57.         <TD>
  58.             <TABLE cellpadding="0" cellspacing="0" border="0" width="100%">
  59.                 <TR>
  60.                     <TD align="left"><a href="<cfoutput>#blahblah_blahblah_com#</cfoutput>/"><font color="ffffff"><b>Main Menu</b></font></a></TD>
  61.                     <TD align="right"><font color="ffffff"><b>Bad Emails / Phone Compiler v0.1</b></font></TD>
  62.                 </TR>
  63.             </TABLE>
  64.         </TD>
  65.     </TR>
  66.     <tr>
  67.     <div id="ErrorMessage" >&nbsp
  68.     </div>
  69.     </tr>
  70. <FORM method="post" name="searchform" action="getresults.cfm"  id="searchForm101">
  71. <INPUT type="hidden" name="searchflag" value="2" />
  72.     <TR>
  73.         <TD><b>Email:</b><BR>
  74.           <textarea name="email" cols="80" rows="30" tabindex="1" onChange="checkText(this, this.value)" onClick="checkText(this, this.value)"></textarea></TD>
  75.     </TR>
  76.         <TD align="center"><Input type="submit" name="submitbutton"  value="Search" onClick="return validate()" /></TD>
  77.     </TR>
  78. </FORM>
  79. <!---
  80. <FORM method="post" action="getresults.cfm">
  81. <INPUT type="hidden" name="searchflag" value="1">
  82.     <TR>
  83.         <TD align="center"><br><br><hr><br><INpUT type="submit" name="SHOWALL" value="Show ALL"></TD>
  84.     <TR>
  85. </FORM>
  86. --->
  87. </TABLE>
  88. </CENTER>
  89.  

Once the user submits the query, the output results gets shown on the getresults.cfm page with the email the user entered and the system basically matches the email it finds on the database with the phone # and puts it in the table.


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <cfparam name="searchflag" default="-1">
  4. <!---
  5. <cfparam name="email" default="">
  6. <cfparam name="lastname" default="">
  7. <cfparam name="IDNUM" default="0">
  8. --->
  9.  
  10. <CFIF IsDefined("Form.IDNUM") and (Form.IDNUM NEQ "")>
  11.  <cfoutput>
  12.     <CFQUERY name="GetInfo" datasource="#ODBC_Datasource#">
  13.         Select Gaming_clients.clientid, Gaming_clients.lastname, Gaming_clients.firstname, Gaming_clients.email, Gaming_clients.phone
  14.         from Gaming_clients WITH (NOLOCK)
  15.         WHERE Gaming_clients.idnum = #form.idnum#
  16.         ORDER by Gaming_clients.lastname
  17.     </CFQUERY>
  18. </cfoutput>    
  19. <cfelseif IsDefined("Form.lastname") and (Form.lastname NEQ "")>
  20. <cfoutput> 
  21.     <CFQUERY name="GetInfo" datasource="#ODBC_Datasource#">
  22.         Select Gaming_clients.clientid, Gaming_clients.lastname, Gaming_clients.firstname, Gaming_clients.email, Gaming_clients.phone
  23.         from Gaming_clients WITH (NOLOCK)
  24.         WHERE Gaming_clients.lastname LIKE '%#trim(lastname)#%'
  25.         ORDER by Gaming_clients.lastname
  26.     </CFQUERY>
  27. </cfoutput>
  28. <cfelseif IsDefined("Form.email")and (Form.email NEQ "")>
  29. <cfoutput>
  30.     <CFQUERY name="GetInfo" datasource="#ODBC_Datasource#">
  31.     <cfloop index="i" list="#form.searchflag#" delimiters=" ">
  32.         Select Gaming_clients.clientid, Gaming_clients.lastname, Gaming_clients.firstname, Gaming_clients.email, Gaming_clients.phone
  33.         from Gaming_clients WITH (NOLOCK)
  34.         WHERE Gaming_clients.email LIKE '%#trim(email)#%'
  35.         ORDER by Gaming_clients.lastname
  36.         </cfloop>
  37.     </CFQUERY>
  38. </cfoutput>
  39. </cfif>
  40.  
  41.  
  42. <!---  This redirects to page that shows all resumes
  43. <CFIF ParameterExists(SHOWALL)>
  44.     <CFLOCATION url="viewresumes.cfm">
  45.   <CFABORT>
  46. </CFIF>
  47. --->
  48.  
  49. <HTML>
  50. <HEAD>
  51.     <TITLE>Bad Emails / Phone Compiler v0.1 Results</TITLE>
  52. </HEAD>
  53. <FORM method="post" action="viewresumes.cfm">
  54. <INPUT type="hidden" name="clientid_required" value="Please choose someone to edit.">
  55. <CFOUTPUT>
  56. <INPUT type="hidden" name="searchflag" value="#searchflag#">
  57. </CFOUTPUT>
  58. <BODY bgcolor="ffffff">
  59. <CENTER>
  60. <TABLE bgcolor="dddddd" cellpadding="0" cellspacing="0" border="0" width="500">
  61.     <TR bgcolor="008800">
  62.         <TD colspan="3">
  63.             <TABLE cellpadding="0" cellspacing="0" border="0" width="100%">
  64.                 <TR>
  65.                     <TD align="left"><a href="<cfoutput>#blahblah_blahblah_com#</cfoutput>/"><font color="ffffff"><b>Main Menu</b></font></a></TD>
  66.                     <TD align="right"><font color="ffffff"><b>Bad Emails v0.1</b></font></TD>
  67.                 </TR>
  68.                 <tr><td colspan="2" >
  69. <!---
  70.  
  71. <CFIF IsDefined("Form.IDNUM") and (Form.IDNUM NEQ "")>
  72. <cfoutput>    <h1>IDNUM is - #Form.IDNUM#</h1></cfoutput>    
  73. <cfelseif IsDefined("Form.lastname") and (Form.lastname NEQ "")>
  74. <cfoutput>     <h1>Last Name is - #Form.lastname#</h1></cfoutput>
  75. <cfelseif IsDefined("Form.email")and (Form.email NEQ "")>
  76. <cfoutput>     <h1>email is - #Form.email#</h1></cfoutput>
  77. </cfif>
  78. --->            
  79.                 </td></tr>
  80.             </TABLE>
  81.         </TD>
  82.     </TR>
  83.  
  84. <cfif isDefined("GetInfo.Recordcount")>
  85. <CFIF #GetInfo.Recordcount# IS 0>
  86.     <TR>
  87.         <TD colspan="3" align="center">No matches were found</TD>
  88.     </TR>
  89.     <TR>
  90.         <TD colspan="3" align="center"><a href="search.cfm">New Search</a></TD>
  91.     </TR>
  92. <CFELSE>
  93.   <TR>
  94.         <TD><b>Email</b></TD>
  95.         <td><b>Phone</b></td>
  96.     </TR>
  97. <CFOUTPUT query="GetInfo">
  98.     <TR>
  99.         <TD>#email#</TD>
  100.         <td>#phone#</td>
  101.     </TR>
  102. </CFOUTPUT>
  103.  
  104.     <TR>
  105.         <TD colspan="3">
  106.             <TABLE cellpadding="0" cellspacing="0" border="0" width="100%">
  107.                 <TR>
  108.                     </FORM>
  109.                     <FORM method="post" action="search.cfm">
  110.                     <TD align="center"><INPUT type="submit" value="Go Back"></TD>
  111.                     </FORM>
  112.                 </TR>
  113.             </TABLE>
  114.         </TD>
  115.     </TR>
  116.  
  117. </CFIF>
  118. </cfif>
  119.  
  120.     <!---
  121. <cfelse>
  122.     <TR>
  123.         <TD colspan="3">You may have pushed the "enter" key on the previous page - please <a href="javascript:history.go(-1);">go back</a> and push one of the 2 search buttons.</TD>
  124.     </TR>
  125. </cfif>
  126. --->
  127.  </TABLE>
  128. </CENTER>
  129. </BODY>
  130. </HTML>
  131.  
Aug 1 '08 #3

acoder
Expert Mod 15k+
P: 16,027
On line 32, you could replace "LIKE '%#trim(email)#%'" with "IN ('#trim(email)#')".

Note that this assumes you've validated the input and you should use cfparam/cfqueryparam to prevent sql injection attacks.
Aug 1 '08 #4

P: 3
thanks for your response

Expand|Select|Wrap|Line Numbers
  1. <cfoutput>
  2.     <CFQUERY name="GetInfo" datasource="#ODBC_Datasource#">
  3.     <cfloop index="i" list="#form.searchflag#" delimiters=",">
  4.         Select Gaming_clients.clientid, Gaming_clients.lastname, Gaming_clients.firstname, Gaming_clients.email, Gaming_clients.phone
  5.         from Gaming_clients WITH (NOLOCK)
  6.         WHERE Gaming_clients.email IN ('#trim(email)#')'
  7.         ORDER by Gaming_clients.lastname
  8.         </cfloop>
  9.     </CFQUERY>
  10. </cfoutput>
  11. </cfif>
  12.  
Here is what i have now...this didn't do anything tho...whenever i enter multiple email addresses in the form, it results to no match found
Aug 1 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Sorry, forgot the single quotes around each email. You'll need to do to wrap quotes around each email string. You could treat the string as a list with the comma as delimiter and use cfloop to loop over and add quotes and concatenate again.
Aug 1 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.