【发布时间】:2017-01-15 06:19:32
【问题描述】:
我有两个 PHP 页面。在第 1 页上,创建了一个 临时 表并用 mysql 数据库中的数据填充。我正在尝试将此表存储到 $_SESSION 变量中,以便可以将表放到 page2 上。
现在这是我的方法:
这是第1页代码的(部分):
ob_start();
session_start();
//Select data from temporary table
$result = mysqli_query($mysqli,"SELECT * FROM table");
//store table into session variable
$_SESSION['fase1result'] = $result;
这是第2页的代码:
ob_start();
session_start();
$table = $_SESSION['fase1result'];
echo "<table border='1'>
<tr>
<th>ProductID</th>
<th>ProductName</th>
<th>Fase1</th>
</tr>";
while($row = mysqli_fetch_array($table))
{
echo "<tr>";
echo "<td>" . $row['ProductID'] . "</td>";
echo "<td>" . $row['ProductName'] . "</td>";
echo "<td>" . $row['Fase1'] . "</td>";
echo "</tr>";
}
echo "</table>";
不幸的是,到目前为止,这些脚本在 page2 上返回了一个错误。此时page2上的table的回显只是为了测试验证table是否真的传过去了。稍后我希望能够使用 MySQL 查询进一步向表中添加数据。希望你能帮助我。
更新:
我得到的错误是:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in domain/page2.php on line 32
page2 中的第 32 行是:
while($row = mysqli_fetch_array($table))
为了更好地解释我的问题,我发布了另一个问题,可以在这里找到: Modifying MySQL table on different pages with scores from a HTML form
【问题讨论】:
-
抱歉忘记了。我已经更新了我的问题。
-
检查$result有记录吗??
-
$result = mysqli_query($mysqli,"SELECT * FROM table") or die(mysqli_error($mysqli));你看到了什么? -
mysqli_fetch_array(result,resulttype);你的语法不好
-
问题不在这里,问题是因为他的查询没有运行,要么是因为 $mysqli 不是到数据库的好链接,要么是因为查询语法错误。
标签: php mysqli html-table session-variables