Smarty:数组到表

<table class="table table-striped table-framed table-centered">
    <thead>
        <tr>
            {foreach from=$columns key=num item=columninfo}
                <th><font color="black">{$columninfo.columnname}</font></th>
            {/foreach}
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        {foreach from=$rows key=num item=rowinfo}
            <tr>
                <td><font color="black">{$rowinfo}</font></td>
                <td><a href="database.php?action=viewtable&table={$tableinfo.tablename}&database={$currentdatabase}"><input class="btn btn-danger" type="button" value="Delete" onclick="return confirm('Are you sure you would like to delete this row?');"/></td></a>
            </tr>
        {/foreach}
    </tbody>
</table>

I've been trying to make it output all the data in the arrays, but the second array, $rows, does not output anything.

The first one works great, and outputs all the names of the columns.

The second array looks like this.

Array ( [0] => Array ( [ID] => 3 [Name] => Eirik [Age] => 20 ) )

What I'm trying to do is to create a database management system where you can access your databases and see tables, columns and rows. Currently I'm only missing rows to complete. It fetches all the column names, and makes the table header, then goes over to rows. The problem here is that when I'm trying to print the rows into the table, I can't use the column name to access the array, due to the column names being different for every database.

You're on the right track: Just follow the same pattern used inside the first foreach.

$rowinfo is an array, and you need to access its elements if you want to print them. Simply write $rowinfo['ID'] (or $rowinfo.ID) to access the ID element of the $rowinfo array.

Repeat for every element you want to print.

A side note: you can use the cleaner PHP syntax for your foreach block:

{foreach $rows as $num => $rowinfo}

is equivalent to

{foreach from=$rows key=num item=rowinfo}

but in my opinion much more readable.

Regarding the EDIT, how to print a dynamic array which has varying columns (names and possibly their number) you can try the following approach:

 {foreach $rows as $num => $rowinfo}
      <tr>
          <td>
          {foreach $rowinfo as $key => $value}
              {$key}: {$value} {* /*of course you'll need to decide HOW to render them */ *}
          {/foreach}
          </td>
          <td>[...]</td></a>
      </tr>
 {/foreach}

Basically you're cycling all the rows you've got in your second array with the outer foreach. Inside the inner one you're cycling over the content of a single row, picking its keys (the column name) and their associated values.