我想在PHP中创建一个网格,并在所选单元格中显示值与数据库单元格值匹配的值。如何在PHP中创建和显示多维数组
网格例如:
A1|B1|C1|D1|E1|F1|G1|H1|
A2|B2|C2|D2|E2|F2|G2|H2|
A3|B3|C3|D3|E3|F3|G3|H3|
在数据库我有一个名为cell_address
包含像[A1,A2,D3,H3]
值柱;
如何将数据库值放入网格中?
我想在PHP中创建一个网格,并在所选单元格中显示值与数据库单元格值匹配的值。如何在PHP中创建和显示多维数组
网格例如:
A1|B1|C1|D1|E1|F1|G1|H1|
A2|B2|C2|D2|E2|F2|G2|H2|
A3|B3|C3|D3|E3|F3|G3|H3|
在数据库我有一个名为cell_address
包含像[A1,A2,D3,H3]
值柱;
如何将数据库值放入网格中?
试试这个:
<?php
$cell_address = "[A1,A2,D3,H3]";
$ar_columns = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
$ar_rows = array('1', '2', '3');
$ar_addresses = explode(",", substr($cell_address, 1, -1));
$html = "<table>
<tr>
<th></th>
<th>".implode("</td><td>", $ar_columns)."</th>
</tr>\n";
foreach($ar_rows as $row)
{
$html .= "<tr><th>".$row."</th>\n";
foreach($ar_columns as $col)
{
$cell_str = (in_array($col.$row, $ar_addresses) ? "match" : " ");
$html .= "<td>".$cell_str."</td>\n";
}
$html .= "</tr>\n";
}
$html .= "</table>\n";
echo $html;
只需用mysql_fetch_array()从数据库中读取数据,并在网格中显示它...
对于这样的问题,我只能说:阅读说明书(例如this其中也包含例子)并且学习语言基础知识
它的一个好主意。非常感谢你。我已经做到了,但你高智商的想法,我会改变我的想法与我... – saint 2011-03-20 07:20:58