views:

39

answers:

1

I currently have about 4 different database tables which output to html tables. Each of these tables uses a count query to calculate data from a 5th table.

That's no problem, but what about when I want to sort and order the data, and paginate etc (like with zend). If it were a one page table, I could probably sort an array.

My thought was, to use a ticker. But that would require a new column in all 4 tables and seems like overkill or like there could be a better way.

Sadly, I can't find much info on it (likely because I don't know what to search for).

Advice?

..and please take it easy, I'm new and learning.

+1  A: 

Assuming youre using Zend_Db_Table_Row and that you dont need to persist any modifications you might make to these rowsets then you can just append the virtual columns to the row object and have them be accessible via array notation. So if youre doing it all in one query now just use that same query, and the column should be there.

OTOH, if youre using a Data Mapper pattern then simply adjust your hydration to look for this "virtual column" and hydrate it if it exists in the result data. Then in your getter for this property have it see if the property is null or some other negative specification, and if it is, to execute a calculation query on that single object or return the already calculated result.

prodigitalson
Thanks! That sounds perfect. Do you have a link where I can find more information about implementing virtual columns and such. I use Mappers which extend an abstract mapper. I have a getter for the property within the relevant mappers, but can't figure out how I would sort that property when I have an array of Mappers to loop through. i.e. having the data sorted prior to the loop.
Zenph
Why would you have an array of mappers? shouldnt you have an array of objects? ie. Mappers issue queries and handle hydration and persisting the data objects, but in your view or with a paginator iw ould thing youd have a data object or a collection object... I Dont have any specfici links to a turotial but if you want o post sample schema and your query(ies) i might be inclined to give you a skeleton example...
prodigitalson