php - 从表中选择全部并显示结果mysql

标签 php mysql

<?php
   $query_announcement = mysql_query("SELECT * FROM announcement");
   $get_announcement = mysql_fetch_assoc($query_announcement);
?>

  <?php
        if(mysql_num_rows($query_announcement) > 0){
            $row = mysql_num_rows($query_announcement);

               for($x = 1; $x<= $row; $x++){

               $html = '<tr>';
               $html .= '<td>'.$get_announcement['id'].'</td>';
               $html .= '<td>'.$get_announcement['announce_name'].'</td>';
               $html .= '<td>'.$get_announcement['announce_description'].'</td>';
               $html .= '<td>'.$get_announcement['announce_location'].'</td>';
               $html .= '<td>'.date('M d,Y', strtotime($get_announcement['date_start'])).'</td>';
               $html .= '<td>'.date('M d,Y', strtotime($get_announcement['date_end'])).'</td>';
               $html .= '<td>'.date('M d,Y', strtotime($get_announcement['date_added'])).'</td>';
               $html .= '<td width="15%">

              <button type="button" class="btn btn-default" title="Edit"><span class="fa fa-pencil"></span></button>
              <button type="button" class="btn btn-default" title="Delete" ><span class="fa fa-trash-o"></span></button>
              </td>';
              $html .= '</tr>';

              echo $html;
              }
           }
               else{
                echo '<tr><td colspan="8" align="center"><h3>No Announcement</h3></td></tr>';
              }
    ?>

/这是我的代码,但当我运行它时,我只收到具有相同 id 的公告,而不是我创建的所有公告。请帮忙谢谢

最佳答案

您正在循环播放该公告,但不会拉出下一个公告。

for($x = 1; $x<= $row; $x++){
//Pull next record
$row = mysql_num_rows($query_announcement);

如果将其更改为上面的代码,for 循环将启动。数据将被拉取、显示,然后再次循环。

关于php - 从表中选择全部并显示结果mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30172636/

相关文章:

php - 如何在 Symfony2 之外启用 ORM 注释前缀?

php 抓取 HTML - 仅限 IE 的问题

php - 使用 CI DataMapper ORM 连接不同数据库中的表

mysql - 从命令行运行 MySQL

php - TinyMCE MySQL 和 html 标签

mysql - 加速 MySQL 查询(包括子查询连接)?

php - div 和类未显示

python - 在 docker 中连接到 mysql 服务器

php - 如何 mysql_fetch_assoc 用于 OR 运算符中给出的两个选择语句以选择任一表

php - 如何将 Symfony 形式的 MoneyType 输入覆盖为 ="number"类型?