【发布时间】:2025-11-26 19:25:02
【问题描述】:
system/article.php
<?php
$sql = "SELECT articleTitle, articleSummary, articleContent FROM articles";
$result = $dbconnect->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $row["articleTitle"];
echo $row["articleSummary"];
echo $row["articleContent"];
}
} else {
echo "0 results";
}
include 'template/homepage.php';
从文章表中检索文章。
我已经包含了应该作为模板的 homepage.php。
template/homepage.php
<?php include 'template/common/header.php'; ?>
<h1>Article Title here</h1>
<p>articleSummary</p>
<?php include 'template/common/footer.php'; ?>
我现在如何将检索到的数据传递给 homepage.php 以在浏览器上显示?
编辑
smarber 指给我看
在第一个文件中:
global $variable;
$variable = "apple";
include('second.php');
在第二个文件中:
echo $variable;
有效。但是我该如何解决我的问题呢?
【问题讨论】:
-
为了更好地帮助您,您打算循环获取的数据是什么?
-
@someOne,需要在首页发布所有文章在表格中
-
含糊不清!那么,为什么不直接从主页获取数据呢? (我的意思是为什么不在首页查询数据库?)
-
@someOne,嗯,让我看看我最终得到了什么....谢谢