该变量在函数内不可访问。当我在函数外回显变量时,我得到了正确的结果。当我在函数内回显/使用变量时,我得到一个“注意:未定义变量:/setup.php 中的 crLocalIncompleteStatus 35”有任何想法吗?<?php global $wpdb; $table_name = $wpdb->prefix . 'crLocal'; $crLocalIncompleteStatus = ''; $crLocalCompleteStatus = ''; $crLocal_DBChecked = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); function crLocal_CheckDB() { global $crLocal_DBChecked, $crLocalIncompleteStatus, $crLocalCompleteStatus; if ($crLocal_DBChecked == '0') { $crLocalIncompleteStatus = 'block' ; $crLocalCompleteStatus = 'none' ; } elseif ($crLocal_DBChecked != '0') { $crLocalIncompleteStatus = 'none' ; $crLocalCompleteStatus = 'block' ; } else { // Broken // More Code to follow } echo $crLocal_DBChecked; } crLocal_CheckDB(); $crLocalInstallIncomplete = '<div id="crLocalInstallIncomplete" style="display: '.$crLocalIncompleteStatus.';">' ; $crLocalInstallComplete = '<div id="crLocalInstallComplete" style="display: '.$crLocalCompleteStatus.';">' ;?>所以我需要:当数据库中的计数为 0 时,$crLocalIncompleteStatus 为 'block',大于 0 时为 'none'。当数据库中的计数为 0 时,$crLocalCompleteStatus 为 'none',大于 0 时为 'block'。
1 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
这是因为您的变量 $crLocalIncompleteStatus 超出了您的函数范围,您可以通过将该变量作为参数添加到函数中来更正此问题
function crLocal_CheckDB($crLocalIncompleteStatus) {
global $crLocal_DBChecked, $crLocalIncompleteStatus, $crLocalCompleteStatus;
if ($crLocal_DBChecked == '0') {
$crLocalIncompleteStatus = 'block' ;
$crLocalCompleteStatus = 'none' ;
} elseif ($crLocal_DBChecked != '0') {
$crLocalIncompleteStatus = 'none' ;
$crLocalCompleteStatus = 'block' ;
} else {
// Broken
// More Code to follow
}
echo $crLocal_DBChecked;
}
crLocal_CheckDB($crLocalIncompleteStatus);
- 1 回答
- 0 关注
- 144 浏览
添加回答
举报
0/150
提交
取消