我试图将表中的结果转换为PHP变量,这样我就可以在连续循环中显示所有结果。目前,使用我的代码,只显示最后的结果。目标是使每个标题和内容结果显示在一个循环中。 TIA求助。
<html>
<head>
<style>
#table1{
border:1px solid #FFFFFF;
background:#FFFFFF;
display:none;
width: 60%;
margin-left: auto;
margin-right: auto;
}
th{
text-align:center;
}
td,th{
border:1px solid #FFFFFF;
text-align:center;
}
</style>
</head>
<? if ($query=$pdo->prepare("SELECT * FROM `Announcements_Current`"))
{
/* select all information from the table and take it into the page */
$query->execute();
while ($result = $query->fetch(PDO::FETCH_ASSOC)){
$head = $result['headline'];
$content = $result['content'];
}
}
?>
<table id="table1" cellpadding="5" cellspacing="1" width="50%">
<tr>
<th>
<h1>
<?php echo $head;
?>
</h1>
</th>
</tr>
<tr>
<td>
<font size="4">
<?php echo $content;
?>
</font>
</td>
</tr>
</table>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
for (var i = 0; i < 500; i++) {
$(document).ready(function() {
$('#table1').fadeIn(2000);
$('#table1').delay(5000);
$('#table1').fadeOut(2000);
}
)};
</script>
</body>
答案 0 :(得分:0)
<html>
<head>
<style>
#table1{
border:1px solid #FFFFFF;
background:#FFFFFF;
display:none;
width: 60%;
margin-left: auto;
margin-right: auto;
}
th{
text-align:center;
}
td,th{
border:1px solid #FFFFFF;
text-align:center;
}
</style>
</head>
<table id="table1" cellpadding="5" cellspacing="1" width="50%">
<? if ($query=$pdo->prepare("SELECT * FROM `Announcements_Current`"))
{
/* select all information from the table and take it into the page */
$query->execute();
while ($result = $query->fetch(PDO::FETCH_ASSOC)){
$head = $result['headline'];
$content = $result['content'];
echo '
<tr>
<th>
<h1>
'.$head.'
</h1>
</th>
</tr>
<tr>
<td>
<font size="4">
'.$content.'
</font>
</td>
</tr>';
}
}
?>
</table>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
for (var i = 0; i < 500; i++) {
$(document).ready(function() {
$('#table1').fadeIn(2000);
$('#table1').delay(5000);
$('#table1').fadeOut(2000);
}
)};
</script>
</body>