the following code that want to get data from mysql database using foreach($result as $post),and output in html ,but it's return null,thx a lot,need your help?
<?php
 $db = mysqli_connect('localhost','xxx','xxx','database')
 or die('Error connecting to MySQL server.');
 mysqli_query($db,"SET NAMES utf8");
?>
<html>
<head>
</head>
<body>
<h1>Demo </h1>
<?php
$query = "SELECT typename,typeurl FROM `posts_table`";
$result = mysqli_query($db, $query);
// output template: 
foreach($result as $post)
{
?>
    <div class="post">
        <p><?=$post['typename']?></p>
        <div class="info">
            posted at <?=$post['typeurl']?>, 
            <a href="./comment-url?id=<?=$post['typeurl']?>"><?=$post['typename']?> comment(s)</a>
        </div>
    </div>
<?
}
?>
</body>
</html>
 
     
    