You are here: Re: Looking for a simple template with "optional" fields « All PHP « IT news, forums, messages
Re: Looking for a simple template with "optional" fields

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]


Удаленная работа для программистов  •  Как заработать на 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

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