我尝试创建一个查询系统,将系统中的所有用户帐户显示给系统管理员,以便稍后我可以添加一个功能来编辑它们等等。我已经创建了一个PHP文件找到结果并创建一个表,然后回显到javascript并显示。但是,系统仅显示0而不显示表。我只能假设这意味着没有找到任何东西,但我的系统意味着要抓住这一点,我90%肯定它应该找到一些东西。
的Javascript
function UserSearch(){
var Search = $("#txtUserSearch" ).val();
var Type = $("#sltQuery" ).val()
$.post('../functions/php/fncusersearch.php', {Search: Search, Type: Type}, function(data) {
if (data == 1){
$('#divSearchResults').html('<p class="text-center text-danger bg-danger" id="pUPInc">No Accounts Matched your Search!</p>');
}
else if (data == 3){
$('#divSearchResults').html('<p class="text-center text-danger bg-danger" id="pUPInc">Database not found! Please try again later.</p>');
}
else{
$('#divSearchResults').html(data);
}
});
}
PHP
//Retrieves variables from Javascript.
$Search = $_POST["Search"];
$Type = $_POST["Type"];
if ($Type == "Registration Date"){
$Type = "joined";
}
else if ($Type == "Account Rank"){
$Type = "rank";
}
include "db/openlogindb.php";
if($DBError == true){
$data = 3;
}
else{
$UserSearch = "SELECT username, surname, forename, joined, rank FROM users WHERE ".$Type." LIKE '%".$Search."%'";
$results = mysqli_query($conn, $UserSearch);
if(mysqli_num_rows($results) == 0){
$data = 1;
}
else{
$data = '';
$data += '<table class="table table-striped">';
while($row = mysqli_fetch_assoc($results)){
$data += "<tr><td>".$row['surname']."</td><td>".$row['forename']."</td><td>".$row['username']."</td><td>".$row['joined']."</td><td>".$row['rank']."</td></tr>";
}
$data += "</table>";
}
}
include "db/closelogindb.php";
echo $data;
?>
答案 0 :(得分:3)
您使用错误的运算符进行连接
$data += '<table class="table table-striped">';
用。替换+符号。
例如
$data .= '<table class="table table-striped">';