gpt4 book ai didi

javascript - SQL不适当的数据填充

转载 作者:行者123 更新时间:2023-12-02 22:23:36 24 4
gpt4 key购买 nike

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 数据,而是在表中显示 undefined。并且 var row 包含 [object][object]

最佳答案

尝试:

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);

关于javascript - SQL不适当的数据填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59138782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com