You are here: Re: sql query builder « PHP Programming Language « IT news, forums, messages
Re: sql query builder

Posted by Kenneth Downs on 07/25/06 17:00

sachu wrote:

> Hi , What i exactly needed is, I need user to build his own query [only
> the SELECT statement] on the client side. Something like user selecting
> column name from the listbox,etc and selecting the condition.
> for example: condition like between two dates or something like based
> on employee name, or product name.
> what i mean to say is, it should work for all possible condition. and
> retrieved data should be displayed in the table.
>
> Am using PHP 5.0, MySQL and IIS
>
> Can anyone provide mean the code snippets similar to the above idea. I
> have very much shortage of time to really do my own.


This cannot be done in a short amount of time, but I can tell you what you
have to have.

First you need a data dictionary, the list of columns and tables. Foreign
keys are very important if you want to allow multi-table queries.

For the very basics, you need then 4 selections for the user:

1) User chooses 1 table (more complex: user picks multiple tables)
2) User chooses columns
3) User chooses columns to order by out of avail columns
4) User manually inputs filter expressions for some columns

Building SQL out of something like this is child's play, for example:

// Assume $cols contains array of chosen columns
$SQL_Cols = implode(',',$cols);
$SQL_OB = implode(',',$cols_orderby);
$sql="SELECT ".$SQL_Cols." FROM ".$table." ORDER BY ".$SQL_OB;

This is of course missing all kind of details, but it should give you some
flavor of how easy it can be, and yet also how long it can take to really
nail down all of the details.

Our own framework has a prototype of this kind of thing. Email me offlist
and I can provide you with a login. The code is all GPL, so you are free
to download it from our site and examine it. But if you use any more than
a few snippets, you have to abide by the terms of the GPL.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация