|
Posted by J.O. Aho on 01/18/08 18:13
Shai Halevi wrote:
> The use-case that I see is this: I have a program that mostly needs to
> display long(ish) lists to the clients, but the lists can be
> customized. Sometime I want to display the first five columns for each
> row, sometime the last four columns, other times only the odd-numbered
> columns, etc.
>
> What I want, is to have only the following in my PHP code:
>
> $qry = "SELECT [[[whatever fields I'm interested in]]] FROM mytable
> WHERE...";
> $res = db_query($qry);
> while ($row = db_fetch_assoc($res)) {
> $template->add_params($row);
> $template->print();
> }
>
You need a simple way to turn on/off columns that you want to display, you
could store the column names in an array, works quite well.
$template->showcolumns($columnsarray);
and then your query could work like
$qry="SELECT ".implode(',',$this->columnarray)." FROM yourtable WHERE ...";
The number of columns is then based on the size of the array and is quite
trivial to implement, I don't think you would be spending more than some ten
fifteen minutes to do it.
--
//Aho
Navigation:
[Reply to this message]
|