Forums

This topic is locked

search page

Posted 02 Apr 2003 21:27:30
1
has voted
02 Apr 2003 21:27:30 Alex Medrano posted:
am having trouble making my search page work, I have a drop down menu with all the months and a wild card "Select All" if i select a month and click on search it works, but if I select "Select All" I get an error that can find any matching records. Does anyone know what value should I give "Select All" for this operation to work.
thanks

gemini.utb.edu/amedrano/records/search.asp


Replies

Replied 02 Apr 2003 22:51:27
02 Apr 2003 22:51:27 Brent Colflesh replied:
Depending on your db, you should use * or %

Regards,
Brent

Replied 02 Apr 2003 22:54:47
02 Apr 2003 22:54:47 Alex Medrano replied:
i have tried that and it still does not work, any other suggestions

thanks
Alex
Replied 03 Apr 2003 04:09:38
03 Apr 2003 04:09:38 Brent Colflesh replied:
If tht is not working, then your query is the problem - post it.

Regards,
Brent

Replied 03 Apr 2003 11:41:31
03 Apr 2003 11:41:31 Julio Taylor replied:
you need to use 'LIKE' in MySQL when you'te using the % wildcard.

e.g.

SELECT * FROM table WHERE field LIKE '%value%'



------------------------
Julio

PHP | MySQL | DWMX | ColdFusion

ICQ: 19735247
Replied 03 Apr 2003 15:21:08
03 Apr 2003 15:21:08 Alex Medrano replied:
search page code

<select name="month" size="1" id="month">
<option value="%" <%If (Not isNull((info_month.Fields.Item("month".Value))) Then If ("%" = CStr((info_month.Fields.Item("month".Value))) Then Response.Write("SELECTED" : Response.Write(""%>>SelectAll</option>
<%
While (NOT info_month.EOF)
%>
<option value="<%=(info_month.Fields.Item("month".Value)%>" <%If (Not isNull((info_month.Fields.Item("month".Value))) Then If (CStr(info_month.Fields.Item("month".Value) = CStr((info_month.Fields.Item("month".Value))) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(info_month.Fields.Item("month".Value)%></option>
<%
info_month.MoveNext()
Wend
If (info_month.CursorType > 0) Then
info_month.MoveFirst
Else
info_month.Requery
End If
%>

results page code
<%
Dim results__MMColParam
results__MMColParam = "1"
If (Request.Form("month" <> "" Then
results__MMColParam = Request.Form("month"
End If
%>
<%
Dim results
Dim results_numRows

Set results = Server.CreateObject("ADODB.Recordset"
results.ActiveConnection = MM_records_STRING
results.Source = "SELECT Count(*) FROM main WHERE month = '" + Replace(results__MMColParam, "'", "''" + "'"
results.CursorType = 0
results.CursorLocation = 2
results.LockType = 1
results.Open()

results_numRows = 0
%>
Replied 03 Apr 2003 15:23:45
03 Apr 2003 15:23:45 Alex Medrano replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
you need to use 'LIKE' in MySQL when you'te using the % wildcard.

e.g.



SELECT * FROM table WHERE field LIKE '%value%'



------------------------
Julio

PHP | MySQL | DWMX | ColdFusion

ICQ: 19735247
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Whne you say
SELECT * FROM table WHERE field LIKE '%value%'
what do you mean by value?

thanks
Replied 03 Apr 2003 16:03:17
03 Apr 2003 16:03:17 Julio Taylor replied:
well-

the value needs to be either a static parameter you enter into the query, or a _GET variable you pass on from the previous page (as will be the case with a search / results scenario).... so:

for example's sake, we will make a very simple search / result pageset

1) on your search page, make a form with a textfield, let's call it "txtSearch", with a button, GET method etc.. i'm sure you've done this already.

2) the results page will have a query. use the following SQL (enter this into advanced mode)

<pre id=code><font face=courier size=2 id=code>
SELECT * FROM table WHERE field LIKE '%vSearch%'
</font id=code></pre id=code>
then you need to specify the 'vSearch' variable, at the lower part of the screen:

name: vSearch
def value: %
run-time value: $HTTP_GET_VARS["txtSearch"] (you can replace this with whatever the name of your textfield)

so, basically, what you are doing is replacing the '=' with 'LIKE' and surrounding the criteria with '% %'... it works much the same as the '=' method, except it will return all your records, since it's using the '%' wildcard as the default value (which is used when the GET variable is not set).

let me know how you get on!

what database are you using? the above is for MySQL.

------------------------
Julio

PHP | MySQL | DWMX | ColdFusion

ICQ: 19735247

Edited by - poolio on 03 Apr 2003 16:04:51
Replied 03 Apr 2003 18:35:33
03 Apr 2003 18:35:33 Alex Medrano replied:
Julio,

thanks for all your help, your solution worked perfectly, now everyting is working.
again thank you very much

Alex

Reply to this topic