ให้ checkbox แสดง 3 ตัวต่อ 1 แถว
ให้ checkbox แสดง 3 ตัวต่อ 1 แถว เงื่อนไขเช็คแล้ว ทำไมมันยังแสดง แถวเดี่ยวคะ
ช่วยหน่อย
<?php
$sqloriginal = "SELECT * FROM AAAAwhere AAAsub='' ";
$queryorigi = mysql_query($sqloriginal);
$i=1;
while($roworigi = mysql_fetch_array($queryorigi)){
echo "<table width=\"60%\" border=\"1\">";
echo "<tr>";
echo "<td width=\"20%\"><input name=\"originalSelect[]\" type=\"checkbox\" value=".$roworigi['ID']."> ".$roworigi['Name']."</td>";
if(($i%3)==0){
echo "</td>";
echo "</tr>";
echo "</table>";
}
$i++;}
?>
ช่วยหน่อย
<?php
$sqloriginal = "SELECT * FROM AAAAwhere AAAsub='' ";
$queryorigi = mysql_query($sqloriginal);
$i=1;
while($roworigi = mysql_fetch_array($queryorigi)){
echo "<table width=\"60%\" border=\"1\">";
echo "<tr>";
echo "<td width=\"20%\"><input name=\"originalSelect[]\" type=\"checkbox\" value=".$roworigi['ID']."> ".$roworigi['Name']."</td>";
if(($i%3)==0){
echo "</td>";
echo "</tr>";
echo "</table>";
}
$i++;}
?>
1.<table>, </table> ไม่ควรอยู่ใน while
2.เงื้อนไขน่าจะมากกว่านี้ ไม่น่าจะใช้ if($%3==0)
3.น่าจะพอเป็นแนวทางได้
<table width="70%" border="0" cellpadding="0" cellspacing="0">
<?
$col = 1;
$sqloriginal= "SELECT * FROM tbloriginal where Original='' ";
$queryoriginal = mysql_query($sqloriginal);
$num_row = mysql_num_rows($queryoriginal);
for($r=0; $r<$num_row; $r=$r+$col){
echo "<tr valign=\"top\">";
for($c=0; $c<$col; $c++){
$rc=$r+$c;
if($rc<$num_row){
$ID_DataOriginal = mysql_result($queryoriginal ,$rc,'ID_DataOriginal');
$Name_DataOriginal = mysql_result($queryoriginal ,$rc,'Name_DataOriginal');
echo "<td><input name=\"originalSelect[]\" type=\"checkbox\" value=".$ID_DataOriginal."> ".$Name_DataOriginal."</td>";
}
}
$col2 = 3;
$sqlsuboriginal1="SELECT * FROM tbloriginal where Original='".$ID_DataOriginal."'";
$queryoriginal1 = mysql_query($sqlsuboriginal1);
$num_row1 = mysql_num_rows($queryoriginal1);
for($r1=0; $r1<$num_row1; $r1=$r1+$col2){
echo "<tr height=\"30\">";
for($c1=0; $c1<$col2; $c1++){
$rc1=$r1+$c1;
if($rc1<$num_row1){
$ID_DataOriginal1 = mysql_result($queryoriginal1,$rc1,'ID_DataOriginal');
$Name_DataOriginal1 = mysql_result($queryoriginal1,$rc1,'Name_DataOriginal');
echo "<td> <input name=\"originalsubSelect[]\" type=\"checkbox\" value=".$ID_DataOriginal1.">".$Name_DataOriginal1."</td>";
}
}
echo "</tr>";
}//end for sub
echo "</tr>";
}/// end for main
?>
</table>