我試圖弄清楚為什么我的 w3 學校 ajax 資料庫拉取示例的 1 對 1 副本僅提取第一個客戶價值的資料。我正在運行的代碼是 w3 學校的 1 對 1 副本,其中我的服務器資訊代替了他們的資訊。我添加了他們在我的資料庫中顯示的相同資訊。
我在 w3 學校制作了以下練習的 1 對 1 副本。

我使前端成為他們前端的完美副本:
<!DOCTYPE html>
<html>
<style>
th,td {
padding: 5px;
}
</style>
<body>
<h2>The XMLHttpRequest Object</h2>
<form action="">
<select name="customers" onchange="showCustomer(this.value)">
<option value="">Select a customer:</option>
<option value="ALFKI">Alfreds Futterkiste</option>
<option value="NORTS ">North South</option>
<option value="WOLZA">Wolski Zajazd</option>
</select>
</form>
<br>
<div id="txtHint">Customer info will be listed here...</div>
<script>
function showCustomer(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
}
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("txtHint").innerHTML = this.responseText;
}
xhttp.open("GET", "getcustomer.php?q=" str);
xhttp.send();
}
</script>
</body>
</html>
然后我添加了我自己的服務器資訊來代替 nottelling、noway、notachance 和 nope:
<?php
$mysqli = new mysqli("nottelling", "noway", "notachance", "nope");
if($mysqli->connect_error) {
exit('Could not connect');
}
$sql = "SELECT CustomerID, CompanyName, ContactName, Address, City, PostalCode, Country
FROM customers WHERE CustomerID = ?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $_GET['q']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($cid, $cname, $name, $adr, $city, $pcode, $country);
$stmt->fetch();
$stmt->close();
echo "<table>";
echo "<tr>";
echo "<th>CustomerID</th>";
echo "<td>" . $cid . "</td>";
echo "<th>CompanyName</th>";
echo "<td>" . $cname . "</td>";
echo "<th>ContactName</th>";
echo "<td>" . $name . "</td>";
echo "<th>Address</th>";
echo "<td>" . $adr . "</td>";
echo "<th>City</th>";
echo "<td>" . $city . "</td>";
echo "<th>PostalCode</th>";
echo "<td>" . $pcode . "</td>";
echo "<th>Country</th>";
echo "<td>" . $country . "</td>";
echo "</tr>";
echo "</table>";
?>
畢竟,
第一個客戶拉,但表元素沒有被帶到 html。

Then if I try to pull the second customer, it gives the header data, but fails to pull from the database.

The third pulls headers, but, also fails to pull data from the database.

I followed the tutorial faithfully with the exception of taking a / out of the second customer code, removing spacing from the data in the fields (which was causing the import to fail until I did it) and finally I changed some of the zipcodes to remove dashes and spaces just to see if it would help (when trying to import the database).
Am I failing to follow this tutorial in some way? Is there another tutorial that could better illustrate this stuff to me?
uj5u.com熱心網友回復:
問題解決了!當我進行 csv 匯入時,MySQL 資料庫中有一些空格會滑入。值前后的空格。
洗掉空格后,這是固定的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/338079.html
