How to use PHP to generate HTML form to let user do complex searches on a database?
Let's imagine I have a database and I want to programatically allow the user to build queries. I am coding in PHP and will output an HTML form to let the user specify his query.
I know the names of all fields, their types (int/string/date, etc) and maybe also min/max. How can I best present this visually to the user and let him select his queries?
At the moment, my logic is only AND
, because I create a table with an entry for each DB field.
If the original input was开发者_JS百科 free-form text (edit or memo), then I can put <field name><operation><text input field>
where operation
is a drop down list of
contains/doesn't contain/begins./ends/etc
. So he can specify name begins "Mc"
, etc
If the original input was from a drop down list, the operation is just equal/no equal
and he gets to choose again from that drop down list.
For integrs operation is = != > >= =< <
And so on, BUT while I can generate a table row for each and put a checkbox by it, I can't let user specify complex seraches like (name beings"Mc" and salary>50000) || (name !=smith && title!="CEO))
I hope that I explained that understandably. What I guess I am preferably looking for is a FOSS PHP compoinent to help me. Failing that, some advice .... Thanks
I use this to present my tables
http://datatables.net/
You can build the queries however you would like with JS, and MAKE SURE YOU VALIDATE THE DATA SERVER-SIDE
Note: There's a bit of a learning curve here if you're new to jQuery and Json, but IMO it's worth it.
精彩评论