Reputation: 37
I'd like to put the data from a MySQL
table in place (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)
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)
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
My wish is that it looks like:
http://www.cacaushow.net.br/panettone_2012/wish.php
Any suggestions?
Upvotes: 0
Views: 663
Reputation: 625
<td> </td>;
wherever you have empty values instead of not doing anything there. And <tr> after each outer for loop
<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>
Upvotes: 0
Reputation: 88
if you're using html table (like you do in examples) you should always first check if the mysql field is empty. if it is replace it with & nbsp ; value. empty table cells (in some browsers) tend to show results like in your first example.
hope this was helpfull...
Upvotes: 2