我的数据库名为:棒球,我要显示的表格名为:球员。
我创建了一个数据库,其中包含不同的棒球队和棒球队的不同球员。
例如,在我的 Teams 表中,球队名称“Red Sox”的 teamID 为“2”,该主键链接到“team”下的 Players 表。现在我有一些以“2”为团队的玩家。
我创建了一个 html 文件,希望仅显示 2 号球员作为球队下显示的数据。
这是我到目前为止一直在搞乱的代码。我终于得到了这个,它没有给我任何错误,但我不知道如何编写一个显示它的函数。
@{
var db = Database.Open("Baseball");
var selectQueryString = @"SELECT firstname , lastname FROM Players WHERE team = 2";
}
最佳答案
试试这个。
@{
var db = Database.Open("Baseball");
var selectQueryString = "SELECT firstname, lastname FROM Players WHERE team = 2";
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<thead>
<tr>
<th>First Name </th>
<th>Last Name </th>
</tr>
</thead>
<tbody>
@foreach(var row in db.Query(selectQueryString)){
<tr>
<td>@row.firstname</td>
<td>@row.lastname</td>
</tr>
}
</tbody>
</table>
</body>
</html>
关于html - 以 html 显示我的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27456175/