Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

query construction from cgi perl params

by ghosh123 (Monk)
on Jul 25, 2012 at 18:27 UTC ( #983712=perlquestion: print w/ replies, xml ) Need Help??
ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monk

I have a webpage from which I am selecting some values to construct my sql query in my cgi script. For exanple, the webpage has the following content as its page source ,

<html> <table> <tr> <td><select name='OPENBRACK1'> <option value=''></option> <option value='('>(</option> </td> <td> <select name='FIELD1'> <option value='CITY'>CITY</option> <option value='NAME'>NAME</option> </select> </td> <td > <select name='COMP1'> <option value='like'>like</option> <option value='notlike'>not like </option <td> <input type=text name='VALUE1' maxlength=40 size=30 value=''></td> <td ><select name='CLOSEBRACK1'> <option value=''></option> <option value=')'>)</option> </td> <tr> <td colspan=7 align=center> <input type='hidden' name='NoOfRows' value="1" /> <input type="button" value="Add Condition" onclick="addRowToTable();" +name="AddCondition" /> </td> </tr> </table> </html>

By the "Add condition" button , I add a similar line of table data in the webpage. And assume that, I collect all these param infos in my cgi script as,

$br1 = $cgi->param('OPENBRACK1'); $field1 = $cgi->param('FIELD1'); $value1 = $cgi->param('VALUE1'); $comp1 = $cgi->param('COMP1'); $br2 = $cgi->param('OPENBRACK2'); $field2 = $cgi->param('FIELD2'); $value2 = $cgi->param('VALUE2'); $comp2 = $cgi->param('COMP2');

So, upon submitting all these in a form, assume that I have all these infos in my cgi script. Now from these param infos how can I contruct a query like this :

select NAME,CITY from MyTable where NAME like %xyz% and CITY not like %abc%;

Please help me with the logic or if there is any other built-in mechanism in cgi perl (some function or ENV variables) which will help me construct such a query.
The diffculty I am facing is how many 'AND' or 'OR' conditions have been used by 'Add condition' button or so.Hope I could explain my problem clearly.

Thanks.

Comment on query construction from cgi perl params
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://983712]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2014-09-16 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (33 votes), past polls