SQL不适当的数据填充

时间:2019-12-02 12:17:29

标签: javascript php jquery html sql

PHP代码

 $qBasicRslt = mysqli_query($conn , $qBasic) or die(mysqli_error($conn));
$json_array[] = array();
while($row = mysqli_fetch_array($qBasicRslt))
{
 $json_array[] = $row;
}
echo json_encode($json_array);

SQL查询_

SELECT  `user`.`passwrd` AS Pass, `user`.`status` AS status,
        `useraccounts`.`Balance` AS bal, `useraccounts`.`AccountID` AS AccID,
        `accounts`.`AccountNo` AS Accno
FROM `user`
LEFT JOIN `useraccounts` ON `user`.`email` = `useraccounts`.`email`
LEFT JOIN `accounts` ON `accounts`.`AccountID` = `useraccounts`.`AccountID`
WHERE user.email = 'abc@testmail.com'

这就是我的数据发送方式

enter image description here

console.log上的数据是这个

[[],{"0":"12345","Pass":"12345","1":"active","status":"active","2":"0.260000000","bal":"0.260000000","3":"3","AccID":"3","4":"1LKHakRqzYi6K7sSDHmV3FirMUpN9YNMYQ","Accno":"1LKHakRqzYi6K7sSDHmV3FirMUpN9YNMYQ"}]

jquery代码

 success: function(data) {
           for (var i=0; i<data.length; i++) {
             var row = $('<tr><td>' + data[i].Pass+ '</td><td>' + data[i].status + '</td><td>' + data[i].bal +'</td><td>' + data[i].Accno +'</td><td>' + data[i].AccID  + '</td></tr>');            
            $('#wallet').append(row);
        }

此功能不是显示json_encoded数据,而是在表中显示未定义。并且var行包含[object][object]

1 个答案:

答案 0 :(得分:1)

尝试:

success: function(data) {
    var data = JSON.parse(data);
    for (var i=0; i<data.length; i++) {
        var row = $('<tr><td>' + data[i].Pass+ '</td><td>' + data[i].status + '</td><td>' + data[i].bal +'</td><td>' + data[i].Accno +'</td><td>' + data[i].AccID  + '</td></tr>');            
        $('#wallet').append(row);
    }

和PHP:

$qBasicRslt = mysqli_query($conn , $qBasic) or die(mysqli_error($conn));
$json_array = array();
while($row = mysqli_fetch_array($qBasicRslt))
{
 $json_array[] = $row;
}
echo json_encode($json_array);