christh Posted April 8, 2010 Share Posted April 8, 2010 Hi all - maybe somebody can help? I want to create a form where a user will input a search criteria which will then query my database - Now all the obvious bits to this request (the form, passing the data, and querying the database) I can do, I'm looking for help and advice on how best to create the search syntax string. I'll explain - with the form a user enters KW1(keyword), OP1(operator), KW2, OP2, KW3, OP3, KW4 eg the form input may read Apples OR Oranges AND Pears OR Melons. Now I need to take this and turn it into a correctly syntaxed query string like (Apples OR Oranges) AND (Pears OR Melons) or (Apples OR Oranges OR Pears) AND Melons My idea was then to build a string from the input ($search=$kw1.$op1.$kw2.$op2 etc) and analyse the structure to ensure the brackets go in the correct places. I tried to construct it using IF statements to insert brackets - this sort of worked but was flawed - given that I'd like to use up to 5 search fields and include NOT operators I'm not sure of the best approach. The search will be performed on a large text field in a SQL database so it's not a case of just organising the data correctly. Additionally the form is for internal company usage so malicious use of the form is not a (major) issue. Would anybody have any advice for me or is there a PHP function that could help in some fashion? I'm not entirely sure the above makes any sense to anybody other than me, so feel free to question my sanity or ask for further info. Thanks Chris Link to comment https://forums.phpfreaks.com/topic/198045-create-a-query-string-from-form-input/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.