gpt4 book ai didi

javascript - 如何在html表主体部分中显示数据库中的所有记录

转载 作者:行者123 更新时间:2023-11-28 17:06:04 25 4
gpt4 key购买 nike

This is how the data are being fetched from database

如何在 html 页面正文部分的表格内显示数据

这是我迄今为止尝试过的代码

<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Sample</title>

<script language="javascript" src="bop/scripts/jquery-3.0.0.min.js"></script>
<script src="cw/scripts/common.2.js"></script>

<script>
$(document).ready(function(e) {
$("#but_submit").click(function(e) {
getstandings()
});
});

function getstandings()
{
var url = "sample.aspx";
var data =
{
object:"getstandings",
action:"hello"
};

getItem(url, data, afterGetInformations);
}

function afterGetInformations(data)
{
console.log(data);

var res = $.parseJSON(data).Result
if (res && typeof res === "object" && res != null)
{
status = parseInt(res.RetCode);
if(status == -1)
{
message2("#msg2", res.ErrMsg);
return;
}
}

var objs = $.parseJSON(data).Item;

if (objs && typeof objs === "object" && objs != null)
{
var str = "<div>"+objs[0].club_name+";"+objs[0].mp+";"+objs[0].win+";"+objs[0].draw+";"+objs[0].lose+";"+objs[0].gf+";"+objs[0].ga+";"+objs[0].gd+";"+objs[0].pts+"</div>";

$("#but_submit").after(str);
}
}


</script>
</head>

<body>

<input type="button" value="Submit" id="but_submit"></input>
</body>
</html>

正在从数据库中获取数据。问题是如何将其显示在表格中。

actual expected outcome

最佳答案

试试这个:它将创建一个包含所有记录的表,每行指示一个对象

if (objs && typeof objs === "object" && objs != null)
{
var tbl='<table id="mytable"><tr> <th>ID</th><th>ClubName</th><th>MP</th><th>Win</th><th>Draw</th><th>Lose</th><th>Gf</th><th>Ga</th><th>Gd</th><th>Pts</th></tr>';

for(var i=0;i<obj.length;i++)
{
var tb1+="<tr><td>"+objs[0].id+"</td>
<td>"+objs[0].club_name+"</td>
<td>"+objs[0].mp+"</td>
<td>"+objs[0].win+"</td>
<td>"+objs[0].draw+"</td>
<td>"+objs[0].lose+"</td>
<td>"+objs[0].gf+"</td>
<td>"+objs[0].ga+"</td>
<td>"+objs[0].gd+"</td>
<td>"+objs[0].pts+"</td></tr>";

}
$("#but_submit").after(str);
}

如果您在这方面需要任何帮助,请告诉我。我很乐意为您提供帮助。谢谢

关于javascript - 如何在html表主体部分中显示数据库中的所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55821867/

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