473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Multiple Search Parameters in one Form

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
5 2754
acoder
16,027 Expert Mod 8TB
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
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
16,027 Expert Mod 8TB
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
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
16,027 Expert Mod 8TB
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

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

Similar topics

2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
11
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings...
2
by: dskillingstad | last post by:
I'm trying to set up a parameter query based on an unbound form. This search form has about 5 text boxes where the user can type in values within each box and search a specific table based on the...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
2
by: angie | last post by:
I need to figure out how to create a user interface to search a query, but here's the bad part...I need to account for criteria on at least 7 of the fields. Here's what I'm thinking I need to do:...
11
by: Panlflzs | last post by:
Howdy, I am working on a system where I need a basic HTML form to pass data to a cfm page. The cfm page will then query a database and return any matching data. I am using MySQL. I have my HTML...
9
by: jmartmem | last post by:
Greetings, Perhaps someone can help me resolve what I hope is a simple dilemma... I have one ASP page (TEST_RoadmapData_Search.asp) which contains two list/menus within a form, which, upon...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.