每当我在html中运行php时,无论顺序如何,php总是最后运行。例如; 当我运行时:
<h2>Admin: Events</h2>
<form action="php/admin_event.php" method="post">
Event Name:<input type="text" name="event"><br>
Start Date:<input type="date" name="startdate"><br>
Start Time:<input type="time" name="starttime"><br>
Finish Date:<input type="date" name="finishdate"><br>
Finish Time:<input type="time" name="finishtime"><br>
Venue:<input type="text" name="venue"><br>
<input type="submit" name="submit">
</form>
<table border='1'>
<tr>
<th>Event</th>
<th>Start Time</th>
<th>Start Date</th>
<th>Finish Time</th>
<th>Finish Date</th>
<th>venue</th>
</tr>
<?php
$con = mysqli_connect("localhost","root","","littleathletics");
if(mysqli_connect_errno($con)){
echo "Failed to connect to MySQL.";
}
$result = mysqli_query($con,"SELECT * from events");
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td><?=$row['Event'];?></td>
<td><?=$row['StartTime'];?></td>
<td><?=$row['StartDate'];?></td>
<td><?=$row['FinishTime'];?></td>
<td><?=$row['FinishDate'];?></td>
<td><?=$row['Venue'];?></td>
</tr>
<?php
}
mysqli_close($con);
?>
<hr>
<h2>Admin: Downloads</h2>
<form action="php/admin_downloadupload.php" method="post" enctype="multipart/form-data">...etc
如果(例如)hello在再见之前出现,我会更喜欢它。我的代码有问题吗?如果没有,有没有办法达到预期的效果?
由于我提供的sql数据,我需要在php中编写一些部分。
编辑:整个表格显示在html文档的最后。
答案 0 :(得分:0)
您有一个未公开的<table>
元素。它在第一个PHP代码之前启动,但从未关闭。你可能想在这里关闭它:
<td><?=$row['Venue'];?></td>
</tr>
<?php
}
mysqli_close($con);
?>
</table> <!-- Add this line -->
<hr>
您还应该验证PHP配置中是否启用了短开标记(默认情况下在最近版本中禁用),或者更改echo语句的简写版本:
<?=$row['Event'];?>
为:
<?php echo $row['Event']; ?>
此更改将使您的代码更具可移植性:它可以在启用或不启用短标记标记的服务器上运行。