Hi all, total newbie on this site, and after reading a trying certain explanations I am still at a loss. I have seen numerous threads on this already and am able to get everything working except the query string. I generally let dreamweaver do things for my as I am still coming to grips with hand coding, but now I need help. I have a dropdown box that lists 3 fields in my database(price, berth,new_or_used) I need a person to select 1 from the dropdown list and then enter a text in a textbox to narrow the search on the chosen field. I have that part working and also if I use $_post I can print the name of the field and the textbox on the search result page, but here is where I am stuck, I cannot seem to get the query string right so that I can list the results. Any help will be appreciated.

Recommended Answers

All 5 Replies

I cannot seem to get the query string right so that I can list the results.

Generally, the query string is considered to be the url plus all the $_GET variables that you tack onto it. What is the problem?

Are you referring to constructing the SQL query string based on user's selection of which field you want to search in?

Are you referring to constructing the SQL query string based on user's selection of which field you want to search in?

Yes thanks, i know it gets passed along the url, i just can't seem to work out the sql query for the selection by choosing a field from the dropdown list then a text box search. having trouble building SQL.

Can you show your code or at least auery?

Say $query_type holds one of these values (price, berth,new_or_used), and $search_string contains the search text.

It would be something along the line of:

SELECT * FROM [table name] WHERE $query_type = "$search_string";  // exact match

You can also do pattern match using LIKE:

http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html

Hope that helps,
Steve

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.