grahamb314 Posted November 30, 2013 Share Posted November 30, 2013 (edited) 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: Any ideas? Edited November 30, 2013 by grahamb314 Quote Link to comment Share on other sites More sharing options...
trq Posted November 30, 2013 Share Posted November 30, 2013 Your code is? Quote Link to comment Share on other sites More sharing options...
grahamb314 Posted November 30, 2013 Author Share Posted November 30, 2013 (edited) I tried this but it just said Array, Array.. {html_table loop=$table} Edited November 30, 2013 by grahamb314 Quote Link to comment Share on other sites More sharing options...
denno020 Posted December 1, 2013 Share Posted December 1, 2013 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.