1

ここで、先行入力を試します。JavaScript で動作します。データベースに接続すると、機能しません。plsは何が間違っているかを見つけます。これを行うために利用可能な代替方法があります

<html>
<head>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div style="margin: 50px 50px">
<label for="product_search">Product Search: </label>
<input id="product_search" type="text" data-provide="typeahead">
<label for="product_search">Name Search: </label>
<input id="namesearch" type="text" data-provide="typeahead">
<label for="product_search">Test Search: </label>
<input id="search" name="search" type="text" data-provide="typeahead">
</div>

<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/bootstrap-typeahead.js"></script>

<script>
$(document).ready(function($) {
// Workaround for bug in mouse item selection
$.fn.typeahead.Constructor.prototype.blur = function() {
var that = this;
setTimeout(function () { that.hide() }, 250);
};

$('#product_search').typeahead({
source: function(query, process) {
return ["Deluxe Bicycle", "Super Deluxe Trampoline", "Super Duper Scooter"];
}
});

$('#search').typeahead({
    name: 'search',
    remote: '/search.php?query=%QUERY'
});

$('#namesearch').typeahead({
source: function(query, process) {
return ["Ravindran", "Aravinthan", "Dakshesh"];
}
});


})
</script>

</body>
</html>

ルートフォルダーにある私のdb search.php

<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) 
{
    die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('test')) 
{
    exit;
}

$text = mysql_real_escape_string($_GET['query']);

$sql = 'SELECT id,title FROM games WHERE name LIKE "%'. $text . '%" LIMIT 5';

$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) 
{
    $posts[] = array($row['id'] => $row['name']);
}
echo json_encode($posts);
mysql_close($link);
?>
4

1 に答える 1