Reading the TablePress datastore
-
Yikes! That previous post formatted a bit differently from what I expected. Let’s try again.
Greetings,
I run a high school baseball site (a shared interest?) that uses and displays lots of data in tablular formats. So TablePress has a been a real boon, since so much of what is presented is best done with tables.
Consider schedules. The coach hands me a table with dates, times, and locations (and small amounts of incidental data like whether the game is a scrimmage or a ‘divisional’ game). I import this to a TablePress table, and add columns for Runs (for and against), Hits, and Errors. This TABLE becomes my default data-store.
When a game is played, a site administrator (usually me) goes to the table-row for this game, and adds values into the Runs, Hits, and Errors table entries for this row. Example: Varsity Schedules
But what I would LIKE to be able to do is programatically crawl though this data, adding up cumulative wins, losses, hits, and errors; and comparing the present date to the game date in order to present imminent games, recently played games, etc. (perhaps to populate yet another table.) In understand I may be able to do the sums with your extensions, but how do I accomplish the comparison of dates?
My point is that if the data is a table, whether it is stored in mySql or in TablePress; I will ALWAYS want to display it via TablePress.
So what I really would like — is to be able to read the values of my TablePress table data from my custom PHP code; then do some comparisons and producing some new short-code values (this looks straightforward); then I can use these short-codes to populate another table (ex: a Cumlative Stats table like those shown at:Anderson Baseball. I can take a whack at writing a little plug-in to do all this; but why should I reproduce all the brilliant code you’ve ALREADY written to present my data? I’d only get it wrong several times before I got it right. I want to leverage what you’ve already done to present my data as a table!
Putting all this tabular data in yet another data-store also seems redundant to me, since you’ve already stored all this SAME DATA somewhere in your own database tables. My experience with multiple data-stores is that they tend to become un-synchronized, and inevitably lead to row integrity conflicts. And again, you’ve already done such a good job of it — I’d only get it wrong again several times before I finally reproduce all the storage and retrieval mechanics that you have already accomplished so well.
Best,
-MattHi Matt,
thanks for your post!
Great to see more people using TablePress for baseball sites! 🙂The best way to achieve this should indeed be some PHP code.
For the first part of summing up Hits, errors, wins, etc. the formula functionality (see http://tablepress.org/tablepress-features-formulas/ ) might be sufficient, but for that comparision of the dates you’ll need some custom code.
The Row Filtering Extension from http://tablepress.org/extensions/row-filter/ might be a good starting point here. You could for example write a custom wrapper around that Shortcode that fills thefilterparameter with a certain date, for example.
For the other ideas of using the table as a data store and then generate other tables out of it, the best approach should be to use the available filter hooks in the class-render.php file. For example, you could hook intotablepress_table_render_datawhich will pass the current table (as a two-dimensional array). By checking some custom parameter (that you could “send” via a custom Shortcode parameter), you would know what desired changes you want to make to that array. Then, just make those and return the modified array. TablePress will then continue rendering that exact table.Hope this helps 🙂
Regards,
TobiasTobias,
You are awesome! This is exactly the kind of detail I’m looking for, and thanks for the pointers to the specific code sections — you’ve saved me hours and hours of spelunking! I’m off to code…
-Matt
Hi Matt,
great to hear that this helps! 🙂
And thanks for the donation, I really appreciate it!Best wishes,
TobiasP.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!
The topic ‘Reading the TablePress datastore’ is closed to new replies.