Forums

This topic is locked

search specific field

Posted 14 Jan 2003 14:23:38
1
has voted
14 Jan 2003 14:23:38 jay lee posted:
how do you search keyword in specific field from a table in a database?

I want to put a search function in my web page where user can select and option (say artistname or tittle ...) the key in the key words - so that the result will only return matched key words in that specific field of the table.
Can anyone help me learn how to do that with UD? please

Replies

Replied 14 Jan 2003 14:41:51
14 Jan 2003 14:41:51 Julio Taylor replied:
1) You need to make a page (search.php) with a form, for example:

1 textfield (name: txt_search)
1 drop menu (name: lst_column)
a button

make the form method GET

2) make a second page (results.php)

i. make a table where you want to put your results
ii. make a recordset, with the following query:
<pre id=code><font face=courier size=2 id=code>
SELECT * FROM &lt;table&gt; WHERE VarColumn LIKE '%VarString%'
</font id=code></pre id=code>

then make two variables (using the + button below the SQL window)

Name Default Value Run-time value
---------------------------------------------------------------------------
VarColumn % $HTTP_GET_VARS["lst_column"]
VarString % $HTTP_GET_VARS["txt_search"]

the names of the vars can be changed, but they must be the same in the query and the variable delcaration area. the names of the GET vars ($HTTP_GET_VARS["<i>lst_column</i>"]) must be the same as the names of the components of the forms in the search.php page.

The VarColumn variable will carry the name of the column, so you'll need to make sure you fill it up with the values reflecting the *exact* column names of the table you are searching.

The VarString carries the text from the textbox.

This will give you a nice results query whihc you can apply to a table via the normal way .

I think i covered everything, let me know if you need more help. Sorry if i've gone into too muchg detail, but i'm not sure how much you know <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

I haven't tried it so i'm not 100% sure it works, but let me know if it does.

Cheers!


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

PHP | MySQL | UD4

ICQ: 19735247

Edited by - poolio on 14 Jan 2003 14:43:37
Replied 14 Jan 2003 20:54:09
14 Jan 2003 20:54:09 jay lee replied:
Thanks so much - but i was working with asp and has no knowledge on PHP at all... looks familiar theway you explain it ...if you could help me the asp way .. that'd be great

Reply to this topic