0
<?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>';
              }
    ?>

/this is my code but when i run it i only get the announcement with the same id, not all announcement that i created. please help thanks

  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 11 '15 at 16:48

3 Answers3

1

You are looping the announcement but are not then pulling the next announcement.

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

If you change it to the code above the for loop will start. The data will be pulled, displayed and then it will loop back around again.

Enayet Hussain
  • 908
  • 4
  • 17
  • 33
0

your r fetching data only one time

for($x = 1; $x<= $row; $x++){
$get_announcement= mysql_fetch_assoc($query_announcement);
Subin S V
  • 137
  • 2
  • 12
  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 11 '15 at 16:48
0

Try this: You need to loop through the rows to and use the each row to display them.

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


 if($get_announcement){

  while($row = mysql_fetch_array($get_announcement)) {

               $html = '<tr>';
               $html .= '<td>'.$row['id'].'</td>';
               $html .= '<td>'.$row['announce_name'].'</td>';
               $html .= '<td>'.$row['announce_description'].'</td>';
               $html .= '<td>'.$row['announce_location'].'</td>';
               $html .= '<td>'.date('M d,Y', strtotime($row['date_start'])).'</td>';
               $html .= '<td>'.date('M d,Y', strtotime($row['date_end'])).'</td>';
               $html .= '<td>'.date('M d,Y', strtotime($row['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>';
              }
akr
  • 739
  • 4
  • 15