开发者

Adding a dynamic row into an existing html with php

I would like to add new ROWS and COLUMNS into another existing TABLE within the same page. How could I do that easily?

Here is the code:

$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>

and this is where I display the data but it displays one row only

<?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."&l开发者_如何学JAVAt;/td>
                  <td>".$leclab."<br/>".$lab."</td>
                  <td>".$lectlabt."<br/>".$labtime."</td>
                  <td>".$daylab."<br/>".$labday."</td>
                  <td>".$roomLabroom."<br/>".$labroom."</td>
                  </tr>";
            }
        }
    }
?>


dude as it enter the loop

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

value 0f a=1 and count=0

now first it executes when count=0 and den again wen count=1 bt all dis time value of a remains same that is a=1

now wen count=2 count<=1 (false)

dats why onie 2 rows are displayed

for every row u making different forms so wen submitted a form,data is submitted of one form and wen u run the iteration after post twice in the loop dat value comes two times

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜