I migrated from informix some years back. This is much easier to do in
PHP / mySQL than in informix, and in fact is something that is quite
commonly done. Since you can create sql commands as a string, you can
put together a string just about anyway you want based on conditions
users enter in a form. You could use the same format that Informix uses,
however I choose to make the forms somewhat more clear to the user.
There are exceptions, but I usually display two input areas per field.
One for greater than or equal, and one for less then or equal. They can
enter either field or both. Then simply generate the SQL string based on
the data entered.
For example if you had two fields for price. First is beg_price and
other is end_price.
Upon return of the from from the user I check both fields. The code
would look something like:
$where_and = ' WHERE ';
$beg_price .= '';
$end_price .= '';
$compare = '';
if ($beg_price '') {
$compare .= $where_and price = $beg_price;
$where_and
= ' AND ';
}
if ($end_price '') {
$compare .= $where_and price = $end_price;
$where_and
= ' AND ';
}
$sql =
SELECT *
FROM customers
$compare;
You could let them put in the compare such as '=' and use a single
input field for price, but I found I had more problems trying to explain
that to users. That's your choice. However this seemed to be the easiest
for them to use.
HTH.
Have a great day... Dan
=
Fernando Ortiz wrote:
I'm migrating my code from Informix 4GL to PHP, my problem now is how to
give the users the ability to make a query with the facilities that the
CONTRUCT verb gives in 4GL.
Suppose a form field name 'price' where the users can type the search
criteria
If the user type ... I need to get ...
123.23 price = 123.23
100 price 100
=500price = 500
100..200price between 100 and 200
100,200 price in (100,200)
In a string field named city
If the user type ...I need to get
sacramento city = 'SACRAMENTO'
sacra* city MATCHES 'SACRA*'
Wy city 'WY
etc.
Something like ..
$qbe = qbe('city','options')
$qry = select * from customers where .$qbe;
and the qbe function can get the typed from $_POST[$parm1] and using the
options chose between char or numeric data type , upshift or as is, matches
or like, etc.
Exist something like that?
I'm reinventing the wheel?
How are you solving this kind of problem?
TIA
--
Fernando Ortiz Muñoz
Fabrica de Jabon la Corona, SA de CV
MEXICO
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php