mukeshdak icon

2025-09-29_list a column from a table

mukeshdak | PRO | 09/28/25 06:51:51 PM UTC | 0 ⭐ | 339 👁️ | Never ⏰ | [php, mysql]
PHP |

610 B

|

None

|

0 👍

/

0 👎

<?php
$db = new PDO("mysql:host=103.53.43.235;dbname=dunglskh_mvc_2020", "dunglskh_md", "use-real-password-here");
$posts = $db->query("SELECT * FROM posts")->fetchAll();
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
Following are my posts.
<?php
foreach ($posts as $post) {
    echo "<h2>" . $post['title'] . "</h2>";
}
?>
</body>
</html>

Comments