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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|