Jump to content

smarty array to html table


grahamb314

Recommended Posts

I'm using smarty and have an array called $table

 

Array (

[0] => Array ([0] => title [1] => criteria [2] =>date )

[1] => Array ( [0] => heading[1] => a[2] =>  b[3] => c[4] => d [5] => e[6] => f[7] => g

[2] => Array ( [0] => 1[1] => 0 [2] => 100 [3] => 0 [4] => 4 )

[3] => Array ( [0] => 2[1] => 100 [2] => 0 [3] => 0 [4] => 1 )

[4] => Array ( [0] => 3[1] => 25 [2] => 0 [3] => 75 [4] => 4 )

[5] => Array ( [0] => 4[1] => 22.222222222222 [2] => 0 [3] => 77.777777777778 [4] => 9 )

[6] => Array ( [0] => 5[1] => 0 [2] => 14.285714285714 [3] => 85.714285714286 [4] => 7 )

[7] => Array ( [0] => 6[1] => 50 [2] => 50 [3] => 0 [4] => 8 ) )

 

I want to display this in an html table by using smarty, I cannot work out the smarty syntax to loop the array and get the table to output like this:

 

 

4FtZvys.png

 

Any ideas?

Edited by grahamb314
Link to comment
Share on other sites

the html_table macro is expecting strings in a single array. You can achieve it like this:

 

Your $table array needs to be a single array, with all of the elements that you want. Then in your smarty template, you tell the macro how many columns there are to be in the table, lets use 5 as an example. Smarty will then take the first 5 elements in the array, and print them in the first row, it will then print the next 5 elements on the next row, and so on.

 

The trick with your table is that you will have empty strings in your array, which will be taking up the extra columns in the table for rows that have less fields.

 

Have a crack at that and let us know how you go, if you need more help, come back with the code you've tried :).

 

Denno

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.