如何在PHP之后添加更多HTML?

时间:2016-06-02 10:26:40

标签: php html database

我想将按钮放在的正下方,我使用 PHP 从数据库中检索。但我不知道如何把按钮放在桌子上方,因为它们一直出现在桌子上方。

<html>
<body bgcolor="#E6E6FA"><center>
<h2>Existing Librarian System Access Profile</h2><br><br>
<?php
$hostid= 'localhost';
$user='root';
$pass='';
$db= 'projectdata';
$con = mysqli_connect($hostid, $user, $pass,$db);
mysqli_select_db($con,$db);


$query = "SELECT librarian_id, username, name, ic_no, phone_no, date_created, date_update FROM Librarian";
$run=mysqli_query($con, $query);
            $num_rows=mysqli_num_rows($run);

            if($run===FALSE){
                die(mysql_error());
            }

            if($num_rows>0)
            {
                echo "<table><tr><th>Librarian ID</th><th>Username</th><th>Name</th><th>National ID No</th><th>Phone No</th><th>Date Created</th><th>Date Update</th>";
                while ($row=mysqli_fetch_array($run))
                {   

                $librarian_id=$row['librarian_id'];
                $username=$row['username'];
                $name=$row['name'];
                $id_no=$row['ic_no'];
                $phone_no=$row['phone_no'];
                $date_created=$row['date_created'];
                $date_update=$row['date_update'];

                echo "<tr><td>$librarian_id</td><td>$username</td><td>$name</td><td>$id_no</td><td>$phone_no</td><td>$date_created</td><td>$date_update</td></tr>";
                }
            }?><input type="submit" name="add" value="Add Librarian"><input type="submit" name="delete" value="Delete Librarian"></center></body></html>

4 个答案:

答案 0 :(得分:0)

你可以这样做:

<html>
<body bgcolor="#E6E6FA"><center>
<h2>Existing Librarian System Access Profile</h2><br><br>
<table>
<tr><th>Librarian ID</th><th>Username</th><th>Name</th><th>National ID No</th><th>Phone No</th><th>Date Created</th><th>Date Update</th>




<?php
$hostid= 'localhost';
$user='root';
$pass='';
$db= '';
$con = mysqli_connect($hostid, $user, $pass,$db);
mysqli_select_db($con,$db);


$query = "SELECT librarian_id, username, name, ic_no, phone_no, date_created, date_update FROM Librarian";
$run=mysqli_query($con, $query);
            $num_rows=mysqli_num_rows($run);

            if($run===FALSE){
                die(mysql_error());
            }

            if($num_rows>0)
            {

                while ($row=mysqli_fetch_array($run))
                {   

              $librarian_id=$row['librarian_id'];
                $username=$row['username'];
                $name=$row['name'];
                $id_no=$row['ic_no'];
                $phone_no=$row['phone_no'];
                $date_created=$row['date_created'];
                $date_update=$row['date_update'];
?>
</tr>

<tr> <td><?php echo $librarian_id;?></td><td><?php echo $username;?></td><td><?php echo $name;?></td><td><?php echo $id_no;?></td><td><?php echo $phone_no;?></td><td><?php echo $date_created;?></td><td><?php echo $date_update;?></td></tr>


                <?php
                }
            }?>
            </table>
            <input type="submit" name="add" value="Add Librarian"><input type="submit" name="delete" value="Delete Librarian"></center></body></html>

答案 1 :(得分:0)

 echo "<tr><td>$librarian_id</td><td>$username</td><td>$name</td><td>$id_no</td><td>$phone_no</td><td>$date_created</td><td>$date_update</td></tr>";
                }
           echo '<tr><td><input type=\"submit\" name=\"add\" value=\"Add Librarian\"><input type=\"submit\" name=\"delete\" value=\"Delete Librarian\"></td></tr></table></center></body></html> }?>

答案 2 :(得分:-1)

您没有使用</tr>在标头中关闭tr标记。生成表格行后,您还没有关闭表标记</table>

答案 3 :(得分:-1)

您错过了至少一个HTML标记。将您的HTML复制到this工具中以查看所有HTML错误。