ユーザーがテキストを書き込んだ場合、それは顧客の名前検索は、Ajax、PHPを使用して、ドロップダウンリストになります
<script>
function custlist() {
$.ajax({
url: "custlist.php",
success: function(result) {
$("#customerlist").html(result);
}
});
}
function showCustomers(str) {
$.ajax({
type: "GET",
url: "customerlist.php",
data:'q='+str,
success: function(result) {
$("#customerlist").html(result);
}
});
}
</script>
<input type="text" oninput="showCustomers(this.value)" placeholder="Search here" name="CustomerNo" />
<select name="Cno" id="customerlist" onfocus="custlist()">
<option value="">Customer Name</option>
</select>
custlist.phpのドロップダウンリストが表示されるはずです、入力テキストボックスがあるはずです
<?php
$sql2 = 'SELECT Customer_Name as Cname,No from customers order by Customer_Name';
$result2 = mysqli_query($connection, $sql2);
if (mysqli_num_rows($result2) > 0) { ?>
<option value="">Customer Names</option>
<?php // output data of each row
while($row2 = mysqli_fetch_assoc($result2)) { ?>
<option value="<?php echo $row2['No']; ?>"><?php echo $row2["Cname"]; ?>
</option>
<?php } ?>
<?php } ?>
customerlist.php
<?php
$q = $_REQUEST["q"];
// lookup all hints from array if $q is different from ""
if ($q !== "") {
$sql2 = "SELECT Customer_Name as Cname,No from customers where Customer_Name like '".$q."%s' order by Customer_Name";
$result2 = mysqli_query($connection, $sql2);
if (mysqli_num_rows($result2) > 0) { ?>
<option value="">Customer Names</option>
<?php // output data of each row
while($row2 = mysqli_fetch_assoc($result2)) { ?>
<option value="<?php echo $row2['No']; ?>"><?php echo $row2["Cname"]; ?>
</option>
<?php } ?>
<?php } ?>
<?php } ?>
私はドロップダウンにデータを取得していますが、テキストボックスに何かを書き込むと自動的にその文字と一致するドロップダウンが表示されます。
そして、私が持っているもう一つの問題...
第二号: - 私は最初、「ABD」を入力すると、「それは「ABD」で始まる顧客名を示すが自動的にそれはその後、「AB」で始まる次の名前が表示されますそれでは空です。 なぜですか?
ありがとうございます。
$.ajax({
type: "GET",
url: "customerlist.php",
data:'q='+str,
success: function(result){
$("#customerlist").html(result);
}
});
とPHP:代わりに のJavascriptの
PHPタグを '.php'ファイルであまり開いたり閉じたりする必要はありません。ただ代わりにHTMLをエコーする –