我试图将表中的结果放入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>
最佳答案
<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>
关于javascript - 将MySQL结果放入php变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48373697/