farindra icon

index.php

farindra | PRO | 07/21/18 10:52:32 AM UTC | 0 ⭐ | 266 👁️ | Never ⏰ | []
PHP |

1.05 KB

|

None

|

0 👍

/

0 👎

<?php
require "functions.php";
 
$blog = query("SELECT `id_post`,`title`, `content`, `status`, `date` FROM posts");
 
?>
 
 
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Test Blog</title>
  </head>
  <body>
    <table border="1">
      <tr>
        <td>Title</td>
        <td>Content</td>
        <td>Status</td>
        <td>Date</td>
        <td>Category</td>
      </tr>
      <tr>
      <?php foreach ($blog as $b) : ?>
          <td><?= $b["title"] ?></td>
          <td><?= $b["content"] ?></td>
          <td><?= $b["status"] ?></td>
          <td><?= $b["date"] ?></td>
 
          <?php 
                $id=$b["id_post"]; 
                $categories = query("SELECT c.name_category FROM detail_post dp
                                        LEFT JOIN categories c ON dp.id_category=c.id_category
                                        WHERE dp.id_post=" . $id );
                $categories = implode(", ",array_column($categories ,'name_category'));
           ?> 
 
          <td><?= $categories ?></td>
      </tr>
      <?php endforeach; ?>
    </table>
  </body>
</html>

Comments