我正在为我的网站上的新帐户启用激活队列。
系统将通过迭代每个新用户帐户详细信息的数组来工作,然后显示它们,以便管理员可以接受或拒绝该帐户。要收集帐户详细信息并将其显示在数组中,我使用下面的代码,但是我收到错误“array_push()期望参数1为数组,给定为null”。我不知道为什么会造成这种情况,我已经尝试了以前建议的各种事情。提前谢谢。
<?php
session_start();
require "classes.php";
$TF = new TF_Core ();
$ActQueueQuery = "SELECT username, surname, forename, joined FROM users
WHERE rank = 'Unactivated'";
if ($statement = TF_Core::$MySQLi->DB->prepare($ActQueueQuery)) {
$statement->execute();
$results = $statement->get_result();
}
if($results->num_rows == 0){
$data = 1;
}
else{
$_SESSION["ActQueue"] = "";
while($row = $results->fetch_assoc()){
$_SESSION["ActQueue"] = array_push($_SESSION["ActQueue"], array($row["username"], $row["surname"], $row["forname"], $row["joined"]));
}
$data = 0;
}
echo $data;
?>
答案 0 :(得分:1)
<?php
session_start();
$_SESSION["ActQueue"] = array(); // define an empty array
require "classes.php";
$TF = new TF_Core ();
$ActQueueQuery = "SELECT username, surname, forename, joined FROM users
WHERE rank = 'Unactivated'";
if ($statement = TF_Core::$MySQLi->DB->prepare($ActQueueQuery)) {
$statement->execute();
$results = $statement->get_result();
}
if($results->num_rows == 0){
$data = 1;
}
else{
while($row = $results->fetch_assoc()){
$_SESSION["ActQueue"][] = array($row["username"], $row["surname"], $row["forname"], $row["joined"]); // check the change
}
$data = 0;
}
echo $data;
?>
答案 1 :(得分:0)
“你在$ arr_foundits = array_push上覆盖$ arr_foundits($ arr_foundits,$ it-&gt; ID);.删除$ arr_foundits =,因为array_push不返回数组而是返回int。”芭蕉