我正在使用 codeigniter 生成一个用于插入模板视图的 html 表。不幸的是,这在 1 行中以很长的字符串形式出现,例如:
<table id="myDataTable" class="table table-bordered table-striped" style="clear: both"><tbody><tr><td>id</td><td><a href="#" id="id" data-type="text" data-pk="2" data-url="/post" data-title="id">2</a></td></tr><tr><td>email</td><td><a href="#" id="email" data-type="text" data-pk="2" data-url="/post" data-title="email">A@B.COM</a></td></tr><br><tr><td>notes</td><td><a href="#" id="notes" data-type="text" data-pk="2" data-url="/post" data-title="notes">notes go here</a></td></tr><br> ...
我希望它看起来更像:
<tr>
<td>field1</td>
<td><a href="#" id="field1" data-type="select" data-pk="1" data-value="" data-original-title="Select field1"></a></td>
<td><span class="muted">Select, loaded from js array. Custom display</span></td>
</tr>
<tr>
<td>field2</td>
<td><a href="#" id="field2" data-type="select" data-pk="1" data-value="" data-original-title="Select field2"></a></td>
<td><span class="muted">Select, loaded from js array. Custom display</span></td>
</tr>
这是我的代码:
$string='<table id="myDataTable" class="table table-bordered table-striped" style="clear: both"><tbody>';
foreach ($array as $key => $value) {
$string=$string."<tr><td>$key</td>";
$element='<td><a href="#" id="'.$key.'" data-type="text" data-pk="'.$rowID.'" data-url="/post" data-title="'.$key.'">'.$value.'</a>'.'</td></tr>'."<br>";
$string=$string.$element;
}
$string=$string.'</tbody></table>';
我怎样才能解决这个问题?