Form based queries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
parijke
Forum Newbie
Posts: 2
Joined: Fri Jun 09, 2006 4:31 am

Form based queries

Post by parijke »

Hi all,

We have a database which we want to expose to our users. That database is ment to be queried, but we want an interface upon that database so you can use certain attributes. We are examining if we can do that with php.

Is there some sort of framework out in the open (query builder or so) which can generate optimized SQL queries based upon user selections? So they can click their selecion criteria in a form or so.

Any advice is appreciated.

gr,
Paul
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

If you want to build this yourself, a series of if/else/elseif statements would be the way to go. Gradually building your SQL query.

An example:

Code: Select all

$sqlQuery = 'SELECT * FROM `table` WHERE';

if($_POST['somecriteria'] == $sampleValue){

   $sqlQuery .= " `somefield` = '$someValue";

} else {

   $sqlQuery .= " `somefield` = '$someOtherValue";

}

echo $sqlQuery;
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
parijke
Forum Newbie
Posts: 2
Joined: Fri Jun 09, 2006 4:31 am

Not exactly what I meant

Post by parijke »

Well, thanks for the help but...

I need a little more than that I'm affraid. The idea is that a frontend is able to get the criteria from the user. So they type in postal code froM: .... till .....

We have about 20 attributes to search on, and they can search for more than one criteria.

Those selections must be saved for later adjustments

I think this is done before, so I post my question here. I found something that has a basic idea of mhat I want, call qmaker from Jay Narain.
Post Reply