您可以使用 explode() 函数将数据列中的逗号分隔值转换为数组:
<?php
$result = mysql_query('SELECT rows, columns, data from table_name where id=1');
$record = mysql_fetch_assoc($result);
$rows = $record['rows'];
$columns = $record['columns'];
$data = explode(',' , $record['data']);
if (sizeof($data) != $rows * $columns) die('invalid data');
?>
要显示表格,您需要两个嵌套的 for 循环:
<table>
<?php for ($row = 0; $row < $rows; $row++) : ?>
<tr>
<?php for ($column = 0; $column < $columns; $column++) : ?>
<td>
<?php echo $data[$row * $columns + $column]; ?>
</td>
<?php endfor ?>
</tr>
<?php endfor ?>
</table>