php无法连接js,无法获得从PHP到JS的多个回声

我正在尝试从我的MySQL数据库获得所有具有相同名称的行到我的HTML表。 所以基本上,我的php脚本getRequestToShow.php将值回显到。js文件(该文件通过使用XMLHttpRequest向php脚本请求值)。 然后这个。js文件在HTML表中添加行。

我从php中回显MySQL行,如下所示:$conn = new mysqli($servername, $username, $password, $db_name);

if ($conn->connect_error){

die("Connection failed: " . $conn->connect_error);

}

$id = $_GET['id'];

$id = mysqli_real_escape_string($conn,$id);

$query = "SELECT * FROM `requests` WHERE `name`='$id'";

$result = mysqli_query($conn,$query);

while($row = mysqli_fetch_array($result)) {

echo json_encode(array('first'=>$row['name'],'second'=>$row['amount'],'third'=>$row['date'],'fourth'=>$row['state']));

}

但是我只能从数据库到HTML表中获取值。 如果有多个行具有相同的名称,它将不在HTML表中显示任何内容。function showUser45(str) {

var tableRef = document.getElementById('customers').getElementsByTagName('tbody')[0];

var newRow = tableRef.insertRow(tableRef.rows.length);

var xmlhttp22 = new XMLHttpRequest();

xmlhttp22.onreadystatechange = function() {

if (xmlhttp22.readyState == 4 && xmlhttp22.status == 200) {

if(xmlhttp22.responseText === "") {

var newCell = newRow.insertCell(0);

var newText = document.createTextNode("No earlier withdraws");

newCell.appendChild(newText);

} else {

var h2 = JSON.parse(xmlhttp22.responseText);

var newCell1 = newRow.insertCell(0);

var newText1 = document.createTextNode(h2.first);

var newCell2 = newRow.insertCell(1);

var newText2 = document.createTextNode(h2.second);

var newCell3 = newRow.insertCell(2);

var newText3 = document.createTextNode(h2.third);

newCell1.appendChild(newText1);

newCell2.appendChild(newText2);

newCell3.appendChild(newText3);

if (h2.fourth == 1) {

var newCell4 = newRow.insertCell(3);

var newText4 = document.createTextNode("Completed");

newCell4.appendChild(newText4);

} else {

var newCell5 = newRow.insertCell(3);

var newText5 = document.createTextNode("Pending");

newCell5.appendChild(newText5);

}

}

}

};

xmlhttp22.open("GET","getRequestToShow.php/?id="+str,true);

xmlhttp22.send();

}

这是HTML表的HTML。

UsernameAmountDateState

提前谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值