如何循环依赖在表上
问题描述:
I have problem with looping in table. i want to loop a <td>
, when it reach 10 , it build <tr>
automatically.
Here my code:
$sd=mysql_query("SELECT a.*,b.* FROM surat_jalan a inner join packing_list b on a.id_surat = b.identitas_packing WHERE b.identitas_packing = '$ben[id_surat]' ORDER BY netto_packing ASC");
while($pack=mysql_fetch_array($sd)){
$komapack = number_format($pack['netto_packing'],2);
echo"<td>$komapack</td>";
}
I am stuck on here and don't know what to do but I know how to use mod but " don't know how to loop it.
我在表中循环有问题。 我想循环&lt; td&gt; code>,当它达到10时,它会自动构建&lt; tr&gt; code>。
这是我的代码: p>
$ sd = mysql_query(“SELECT a。*,b。* FROM surat_jalan a aid_surat = b.identitas_packing WHERE b.identitas_packing ='$ ben [id_surat]'内部联接packing_list b'ORDER BY netto_packing ASC“);
while($ pack = mysql_fetch_array($ sd)){
$ komapack = number_format($ pack ['netto_packing'],2);
echo“&lt; td&gt; $ komapack&lt; / td&gt;”;
}
code> pre>
我被困在这里,不知道该怎么做,但我知道如何使用mod,但“不知道如何循环它 。 p>
div>
答
You can use a counter.
$i = 0;
echo "<tr>";
while($pack=mysql_fetch_array($sd)){
$komapack = number_format($pack['netto_packing'],2);
echo"<td>$komapack</td>";
$i++;
if($i % 10 == 0) // check
echo "</tr><tr>";
}
echo "</tr>";
I have problem with looping in table. i want to loop a <td>
, when it reach 10 , it build <tr>
automatically.
Here my code:
$sd=mysql_query("SELECT a.*,b.* FROM surat_jalan a inner join packing_list b on a.id_surat = b.identitas_packing WHERE b.identitas_packing = '$ben[id_surat]' ORDER BY netto_packing ASC");
while($pack=mysql_fetch_array($sd)){
$komapack = number_format($pack['netto_packing'],2);
echo"<td>$komapack</td>";
}
I am stuck on here and don't know what to do but I know how to use mod but " don't know how to loop it.
我在表中循环有问题。 我想循环 我被困在这里,不知道该怎么做,但我知道如何使用mod,但“不知道如何循环它 。 p>
div>&lt; td&gt; code>,当它达到10时,它会自动构建
&lt; tr&gt; code>。
这是我的代码: p>
$ sd = mysql_query(“SELECT a。*,b。* FROM surat_jalan a aid_surat = b.identitas_packing WHERE b.identitas_packing ='$ ben [id_surat]'内部联接packing_list b'ORDER BY netto_packing ASC“);
while($ pack = mysql_fetch_array($ sd)){
$ komapack = number_format($ pack ['netto_packing'],2);
echo“&lt; td&gt; $ komapack&lt; / td&gt;”;
}
code> pre>
You can use a counter.
$i = 0;
echo "<tr>";
while($pack=mysql_fetch_array($sd)){
$komapack = number_format($pack['netto_packing'],2);
echo"<td>$komapack</td>";
$i++;
if($i % 10 == 0) // check
echo "</tr><tr>";
}
echo "</tr>";