So I was hoping to find a pre-built function out there preferably PHP/HTML/JS to recursively display a table in html, but I haven't thus far. I want a really dynamic way of displaying a table from Mongo DB, which as you may know can contain multidimensional data. Java script would come in to collapse / expand any data that is an array.

Anyone know of anything such as this pre-built?

StarLion
—
2013-01-28T18:30:19Z —
#2

how would the data be coming in to the file? I'm not familiar with Mongo's connectors and return structure...

KyleWolfe
—
2013-01-28T18:43:14Z —
#3

It returns an object, which can be converted to a multidimensional array. If you are unfamiliar with how "records" or documents are stored, here might be a good example:

Essentially the "column" forums_liked is an array. Ideally on the fly a script would show each row in a normal table format, but then would allow for arrays to be expanded and viewed. There can be many arrays inside of other arrays, which makes Mongo great IMO. I'm currently looking at using it for a business wide error reporting service. A simple API can be written to require just a few mandatory fields, and then allow a "dump" of an array that each developer would deem necessary info to the error.

StarLion
—
2013-01-28T18:57:44Z —
#4

So it comes in as a JSON which can be flipped into a regular array with json_decode, and then parsed as any normal array would?

KyleWolfe
—
2013-01-28T19:00:58Z —
#5

StarLion said:

So it comes in as a JSON which can be flipped into a regular array with json_decode, and then parsed as any normal array would?

JSON is the format of the db, but not the PHP return. It returns an object, which can be converted to a normal array.

cpradio
—
2013-01-28T19:13:20Z —
#6

Can you provide a var_dump() of that object once PHP has it?

KyleWolfe
—
2013-01-28T19:33:12Z —
#7

Given the example above, and after conversion to an array, it'll look as such:

In my opinion writing your own recursive function to handle the task is nothing complicated and I think it would take you less time than trying to find a ready-made solution and potentially having to adapt it to your needs. This would be using foreach on the array and if there's a another array in the array then you echo a new table and run the same function feeding it the array (that is - considering you want to nest tables inside tables). Then spicing it up with some javascript to toggle display:none on and off on the nested tables shouldn't be complicated either.

KyleWolfe
—
2013-01-28T19:48:11Z —
#10

The recursion its self isn't that hard. However displaying it in a friendly manner will take some time, for me at least. This seems like a generic task that someone would have come across and might have put out a public solution.

Lemon_Juice
—
2013-01-28T19:59:50Z —
#11

Hm, in this case it seems this is more a css/javascript problem than php. It is similar to displaying muli-level menus except this involves tables. I think first you would need to decide how you want this to look and work for the end user (if you haven't done so yet) and then try to find a solution. However, I've never come across anything like this ready-made.

ServerStorm
—
2013-01-29T04:36:27Z —
#12

Being a good programmer you already know how to walk the object, but using something like @StarLion ; 's code