2011-10-15 17 views
0

我想将新的ROWS和COLUMNS添加到同一页面中的另一个现有TABLE中。我怎么能轻松做到这一点?使用php向现有的html添加动态行

下面是代码:

$sql = mysql_query("SELECT * FROM tblsubjecschedule ORDER BY Subject"); 
$i=0; 
$b =1; 
while($row=mysql_fetch_assoc($sql)){ 
    echo "<tr><td>".$row['Subject']."<input type='hidden' name='subj[$i]' value=".$row['Subject']."></td> 
    <td>".$row['Lec']."<br/>".$row['Lab']."<input type='hidden' name='leclab[$i]' value=".$row['Lec']."><input type='hidden' name='lab[$i]' value=".$row['Lab']."></td> 
    <td>".$row['Descriptive']."<input type='hidden' name='desc[$i]' value=".$row['Descriptive']."></td> 
    <td>".$row['Day']."<br/>".$row['Labday']."<input type='hidden' name='daylabday[$i]' value=".$row['Day']."><input type='hidden' name='labday[$i]' value=".$row['Labday']."></td> 

    <td>".$row['LecTime']."<br/>".$row['LabTime']."<input type='hidden' name='lectlabt[$i]' value=".$row['LecTime']."><input type='hidden' name='labtime[$i]' value=".$row['LabTime']."></td> 
    <td>".$row['Room']."<br/>".$row['Labroom']."<input type='hidden' name='roomlabroom[$i]' value=".$row['Room']."><input type='hidden' name='labroom[$i]' value=".$row['Labroom']."></td> 
    <td><input id='send' name='reserv[$i]' type='submit' value='Add' [$b] /></td></tr>"; 
    $i++; 
} 
?> 
</tbody> 
</table> 
<table border="1" style='width: 900px;'> 

<thead> 
<tr> 
    <th>SubjectCode <th>Units <th>Time <th>Day <th>Room</th> 
</tr> 
</thead> 

而这正是我显示该数据,但是,因为它进入循环它显示一列仅

<?php 
    if (isset($_POST['reserv'])){ 
     if(!empty($_POST['reserv'])){ 
      $i = current(array_keys($_POST['reserv'])); 
      $subj=$_POST['subj'][$i]; 
      $leclab=$_POST['leclab'][$i]; 
      $lab=$_POST['lab'][$i]; 
      $labday=$_POST['labday'][$i]; 
      $desc=$_POST['desc'][$i]; 
      $daylab=$_POST['daylabday'][$i]; 
      $lectlabt=$_POST['lectlabt'][$i]; 
      $labtime=$_POST['labtime'][$i]; 
      $roomLabroom=$_POST['roomlabroom'][$i]; 
      $labroom=$_POST['labroom'][$i]; 
     } 
    } 
    if (isset($_POST['reserv'])){ 
     $count=0; 
     $a=0; 
     $c=current(array_keys($_POST['reserv'])); 
     if (!empty($c)){ 
      $a=1; 
      for ($count;$count<=$a;$count++){ 
       echo "<tr> 
        <td>".$subj."</td> 
        <td>".$leclab."<br/>".$lab."</td> 
        <td>".$lectlabt."<br/>".$labtime."</td> 
        <td>".$daylab."<br/>".$labday."</td> 
        <td>".$roomLabroom."<br/>".$labroom."</td> 
        </tr>"; 
      } 
     } 
    } 
?> 
+0

你可以检查'$ a'的值吗? for $($ count; $ count <= $ a; $ count ++){ – ariefbayu

+0

$ a的值为1,但它显示2行,值相同 – nobito

+0

您忘记关闭代码中的** **标记第二张桌子还是写在这里的时候只是打字错误? – punit

回答

0

哥们

for ($count;$count<=$a;$count++) 

值0f a = 1且计数= 0

现在第一执行时计数= 0和DEN再次文计数= 1 BT所有DIS时间值的保持相同即A = 1

现在文计数= 2计数< = 1(假)

反黑组为什么onie 2行显示

的每一行如此文提交表单ü做不同的形式,数据提交一个表单和温家宝ü在循环DAT值后门柱运行迭代两次谈到两次