更新时间:2023-02-05 19:26:38
您做错了方法.
从不将您的数据处理代码与演示代码混合使用.
You are doing it wrong way.
Never mix your data manipulation code with presentation code.
首先创建一个函数以获取帖子:
First make a function to get posts:
function get_posts() {
global $mysqli;
$sql = "SELECT variable_name, post_name, post_date, post_display
FROM blog_posts ORDER BY id DESC LIMIT 5"
$result = mysqli_query($mysqli, $sql);
if (!$result) trigger_error(mysqli_error()."[$sql]");
$date = array();
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
}
这样称呼
require_once 'database.inc.php';
$mysqli = mysqli_connect($host, $username, $password, $database);
$data = get_posts();
然后使用此数组显示