我對index.php頁面有一個完美的查詢。但是當我將查詢移到functions.php時,創建完全相同的查詢,它會中斷。任何想法爲什麼?移動到函數時查詢不起作用
的index.php
<ul>
<?php $cms_sub_pages = cms_find_sub_pages ($file_name); ?>
<?php while($subpage = mysqli_fetch_assoc($cms_sub_pages)) { ?>
<li><a href="/edit.php?
<?php echo $subpage["page_id"]; ?>"><?php echo $subpage["link_name"]; ?></a
</li>
<?php
}
?>
<?php mysqli_free_result($sub_pages); ?>
</ul>
的functions.php
function cms_find_sub_pages ($file_name) {
global $conn;
$query = "SELECT * FROM pages WHERE main_cat = 2 AND category = '{$file_name}' ORDER BY subcategory_order ASC ";
$sub_pages = mysqli_query($conn, $query);
confirm_query($sub_pages);
return $sub_pages;
}
解決:問題是在這裏的index.php:
<?php $cms_sub_pages = cms_find_sub_pages ($file_name); ?>
更改爲:
<?php $cms_sub_pages = cms_find_sub_pages ($mainpage["page_id"]); ?>
,你定義這個變量.' $ file_name' –
我更新的代碼,抄錯行 – user2998254