0
我已經在這裏或谷歌搜索了答案,但是我沒有找到有這個問題的人。 (或我很蠢)變量沒有被轉移到包含文件中
我有一個頁面,創建一個變量,從sql查詢獲取數組,然後,此頁面包含另一個頁面。 但包含的人說我的變量是未定義的。 這裏是我的代碼:
/controller/page1.php
include_once("../model/database_connection.php");
include_once("../model/members.php");
$membersList = selectAllMembers();
foreach ($membersList as $key => $member)
{
$membersList[$key]['pseudo_member'] = htmlspecialchars($member['pseudo_member']);
}
include_once("../view/page1.php");
/view/page1.php
<?php foreach ($membersList as $member)
{ ?>
<div class="table_row">
[...]
</div>
<?php } ?>
錯誤:
Notice: Undefined variable: membersList in C:\wamp\www\project\view\page1.php
/model/members.php
function selectAllMembers()
{
global $mysqli;
$queryString = 'SELECT * FROM `members`';
$queryResult = $mysqli->query($queryString);
$resultArray = false;
if (!$queryResult)
{
echo "selectAllMembers query failed: (" . $mysqli->errno . ") " . $mysqli-error;
}
else
{
$resultArray = $queryResult->fetch_all(MYSQLI_ASSOC);
}
return $resultArray;
}
感謝提前:)
它在哪裏'selectAllMembers()'?它是做什麼的? – fusion3k
顯示代碼爲'include_once(「../ model/members.php」);' –
所以'$ memberList'爲空,如果'selectAllMembers()'沒有返回任何值 – fusion3k