[wp-hackers] Storing Tabular Content in the Database
casey.bisson at gmail.com
Tue Feb 17 19:03:23 GMT 2009
How you might save the data depends on how you'd like to use it. If
all you need to do is display the table (and, perhaps, use the jQuery
table sorter on it, etc.), then you've got a few easy options. On the
other hand, if you need to be able to do more complex operations on
the data, such as search it or join it with other tables, then you'd
probably need a more sophisticated storage scheme (such as the
individual tables you had first suggested).
Starting with the first case, you could create a php array or object
based on the table and save that as post meta. Your plugin could then
read the entry from post meta and generate the table html. You could
also simply save the table html as a string, but that affords you
somewhat less flexibility in the future.
You could also save the tabular data as an attachment in the posts
table (which then makes the strings in it more searchable) and parse
it on display.
How you might handle something more complex is, well, more complex,
but I can point to my library catalog implemented in WordPress, which
turns each book into a post and stores the metadata in the taxonomy
tables. Example: http://library.plymouth.edu/browse More info: http://wordpress.org/extend/plugins/scriblio/
On Feb 17, 2009, at 1:02 PM, Mohammed K. al-Safi wrote:
> My question is about allowing WordPress users to easily display
> content on their blog; providing them with tools to easily do so.
> I'm creating a plugin that will ask the user to select a CSV file
> from their
> HDD and then store the content of this CSV file, *some how*, and
> display it
> as HTML on a page or a post. I know, there already is a plugin by
> Alex Rabe
> called wp-Table. However, I believe there is plenty of room in this
> area for
> another plugin.
> At any rate, I need your help on how I should store the tabular
> content that
> the user uploads via this plugin.
> My first thought was to take a CSV file and create a new MySQL table
> mirrors the CSV file. So, for every CSV file the user wants to
> display on
> the blog, I'd end up with a corresponding MySQL table in WP's
> database. I
> would also create a table to keep track of these CSV tables.
> I explained the aforementioned implementation to some people on irc://
> irc.freenode.net/mysql and they said that this is definitely not the
> way to
> do it. They were talking about database schemas, data normalization
> and some
> stuff that, honestly, I don't think is practicable or applicable for
> plugin. But the people in the IRC channel didn't really understand the
> situation as well as you would, so I want your opinion and help.
> As an alternative solution, I thought that maybe I will generate the
> for the table, and just store that. Kind of like how WordPress would
> store a
> post or something...
> Which implementation should I follow?
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers