javascript - 将MySQL结果放入php变量

标签 javascript php jquery mysql

我试图将表中的结果放入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/

相关文章:

javascript - 使用模式 : no-cors for a request, 时,浏览器未添加我在前端代码中设置的请求 header

javascript - 当我尝试从属性值获取 HTML 数据时,为什么会出现错误?

PHP MySQL表,可重用

javascript - 通过AJAX动态展示大量html

php - 如何跳过 PHPUnit 中的错误测试?

javascript - 如何推迟 Jasmine SpecRunner 的执行

javascript - 仅使用 HTML 和 CSS 进行语法高亮显示

JavaScript 对话框被编程为在页面滚动时移动,但它会闪烁。这可以解决吗?

javascript - booster 在 yii 中通过 jquery 发生冲突

jquery - 如何拖动和定位一个div