我正在创建一个包含三个组件的网站。(我将添加 JQuery 和 CSS,但现在我只是尝试解决一些基本机制)
我的结构是:
- 表示层的 HTML 文件。
- 用于客户端处理的 JAVASCRIPT 文件
- 用于服务器端处理的 PHP 文件。
下面是我的代码:
html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="RipListQuery.js"></script>
<title>CD Riplist Query</title>
</head>
<body onload="getArtists()">
<h1>CD Riplist Query</h1>
<div id="divArtists" >
</div>
</body>
</html>
Javascript:
function getArtists() {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","dataAccess.php",false);
xmlhttp.send();
document.getElementById("divArtists").innerHTML=xmlhttp.responseText;
}
php:
<?php
$con = mysql_connect('myServerAddress', 'ainsworthremote', 'myPassword');
if (!$con) {
die("Could not connect: " . mysql_error());
}
$response =
"<table border='1' id='Artists'><thead><tr><th>Artist</th><th>Albums</th></tr></thead><tbody>";
mysql_select_db("ainsworthremote", $con);
$sql="SELECT artist, COUNT(*) AS albums FROM CD_RipList GROUP BY artist ORDER BY artist ";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$response = $response . "<tr>" .
"<td>" . $row['artist'] . "</td>" .
"<td>" . $row['albums'] . "</td>" .
"</tr>";
}
$response = $response . "</tbody></table>";
mysql_close($con);
echo $response;
?>
我没有像预期的那样得到一个充满艺术家姓名的表格,而是得到以下信息:
CD Riplist 查询
ArtistAlbums"; mysql_select_db("ainsworthremote", $con); $sql="SELECT artist, COUNT(*) AS albums FROM CD_RipList GROUP BY artist ORDER BY artist "; $result=mysql_query($sql); while ($row = mysql_fetch_array($result)) { $response = $response . "" . "" . $row['artist'] . "" . "" . $row['albums'] . "" . ""; } $response = $response . ""; mysql_close($con); echo $response; ?>
我想知道(除了我做错了什么)是:我的标签发生了什么?