[英]Populate html table with php multidimensional array
I'd like to put the data from a MySQL
table in place (HTML Table)
. 我想把
MySQL
表中的数据放到位(HTML Table)
。 Everything is dynamic. 一切都充满活力。 Product names will not always be the same (columns).
产品名称并不总是相同 (列)。 The number of records will not always be the same (rows).
记录数量并不总是相同 (行)。
MySQL Table (populate ROWS data) MySQL表(填充ROWS数据)
iduser idprod quantity date
1234 65 60 2012-11-30 09:13:41.628
1234 66 50 2012-11-30 09:13:41.628
1234 64 80 2012-11-30 09:13:41.628
MySQL Table (populate COLUMNS data) MySQL表(填充COLUMNS数据)
idprod name date
66 Panettone de Truffas 2012-11-29 15:19:41
65 Panettone de Maracujá 2012-11-29 15:16:56
64 Panettone de Brigadeiro 2012-11-29 15:16:44
Code 码
$panettones = array();
$querySel = "SELECT * FROM registro_panettone";
$resultSel = mysql_query($querySel);
$rows = mysql_num_rows($resultSel);
$panettones = array();
for($i=0;$i<$rows;$i++) {
/*$panettones["id_user"] = mysql_result($resultSel,$i,0);
$panettones["id_pan"] = mysql_result($resultSel,$i,1);
$panettones["qtd"] = mysql_result($resultSel,$i,2);
$panettones["data"] = mysql_result($resultSel,$i,3);*/
$retorno = mysql_fetch_array($resultSel);
$texto = "<tr>";
$texto .= "<td>".$retorno[0]."</td>";
$texto .= "<td>".$retorno[1]."</td>";
$texto .= "<td>".$retorno[2]."</td></tr>";
echo $texto;
}
Currently look like: 目前看起来像:
http://www.cacaushow.net.br/panettone_2012/rel.php http://www.cacaushow.net.br/panettone_2012/rel.php
My wish is that it looks like: 我希望它看起来像:
http://www.cacaushow.net.br/panettone_2012/wish.php http://www.cacaushow.net.br/panettone_2012/wish.php
Any suggestions? 有什么建议么?
if you're using html table (like you do in examples) you should always first check if the mysql field is empty. 如果您正在使用html表(就像您在示例中所做的那样),您应该首先检查mysql字段是否为空。 if it is replace it with & nbsp ;
如果是替换它&nbsp; value.
值。 empty table cells (in some browsers) tend to show results like in your first example.
空表格单元格(在某些浏览器中)倾向于显示第一个示例中的结果。
hope this was helpfull... 希望这有用...
<td> </td>;
wherever you have empty values instead of not doing anything there. 只要你有空值而不是在那里做任何事情。 And <tr> after each outer for loop
并且在每个外部for循环之后<tr>
<table border="1" cellspacing="0" cellpadding="5" width="100%">
<tr>
<td><b>Código</b></td>
<td id='66'><b>Panettone de Truffas</b></td>
<td id='65'><b>Panettone de Maracujá</b></td>
<td id='64'><b>Panettone de Brigadeiro</b></td>
<td><b>Data</b></td>
</tr>
<tr>
<td>1234</td>
<td>60</td>
<td>2012-11-30 09:13:41.628</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>1234</td>
<td>50</td>
<td>2012-11-30 09:13:41.628</td>
<td> </td>
<td> </td>
</tr>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.