potrzebuje rozwijaną listę, <select> w której pobierane będą dane z bazy danych. Przy wpisywaniu np. gdy wpiszę G to wyświetli mi wszystkie rekordy zaczynające się na literę G.
W php wczytywanie do formularza jest proste, a takie auto wypełnianie załatwił plugin jQuery Autocomplete.
Tylko że on pobiera dane z pliku js. w którym jej tablica danych.
Jak zrobić żeby dane do tej tablicy pobierane były z bazy danych.
plik localdata.js
Kod
var cities = [
"Aberdeen", "Ada", "Adamsville", "Addyston", "Adelphi", "Adena", "Adrian", "Akron",
"Albany", "Alexandria", "Alger", "Alledonia", "Alliance", "Alpha", "Alvada",
"Alvordton", "Amanda", "Amelia", "Amesville", "Amherst", "Amlin", "Amsden"
];
"Aberdeen", "Ada", "Adamsville", "Addyston", "Adelphi", "Adena", "Adrian", "Akron",
"Albany", "Alexandria", "Alger", "Alledonia", "Alliance", "Alpha", "Alvada",
"Alvordton", "Amanda", "Amelia", "Amesville", "Amherst", "Amlin", "Amsden"
];
plik index.php
Kod
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="files/lib/jquery.js"></script>
<script type='text/javascript' src='files/jquery.autocomplete.js'></script>
<script type='text/javascript' src='localdata.js'></script>
<link rel="stylesheet" type="text/css" href="main.css" />
<link rel="stylesheet" type="text/css" href="files/jquery.autocomplete.css" />
<?php
include ('test.php');
?>
<script type="text/javascript">
$().ready(function() {
$("#suggest1").focus().autocomplete(cities);
$("#singleBirdRemote").result(function(event, data, formatted) {
if (data)
$(this).parent().next().find("input").val(data[1]);
});
});
</script>
</head>
<body>
<div id="content">
<form autocomplete="off">
<p>
<label>Marka:</label>
<input type="text" id="suggest1" />
<input type="button" value="Get Value" />
</p>
<input type="submit" value="Submit" />
</form>
<button id="clear">Wyczyść formularz</button>
</div>
<script type="text/javascript">
_uacct = "UA-2623402-1";
urchinTracker();
</script>
</body>
</html>
<html>
<head>
<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="files/lib/jquery.js"></script>
<script type='text/javascript' src='files/jquery.autocomplete.js'></script>
<script type='text/javascript' src='localdata.js'></script>
<link rel="stylesheet" type="text/css" href="main.css" />
<link rel="stylesheet" type="text/css" href="files/jquery.autocomplete.css" />
<?php
include ('test.php');
?>
<script type="text/javascript">
$().ready(function() {
$("#suggest1").focus().autocomplete(cities);
$("#singleBirdRemote").result(function(event, data, formatted) {
if (data)
$(this).parent().next().find("input").val(data[1]);
});
});
</script>
</head>
<body>
<div id="content">
<form autocomplete="off">
<p>
<label>Marka:</label>
<input type="text" id="suggest1" />
<input type="button" value="Get Value" />
</p>
<input type="submit" value="Submit" />
</form>
<button id="clear">Wyczyść formularz</button>
</div>
<script type="text/javascript">
_uacct = "UA-2623402-1";
urchinTracker();
</script>
</body>
</html>
a tak wyciągnął bym dane z bazy danych:
Kod
$zapytanie = "SELECT * FROM `marka` ORDER BY `id` DESC";
$idzapytania = mysqli_query($mysql, $zapytanie);
while ($wiersz = mysqli_fetch_array($idzapytania)) {
echo '$wiersz['marka']';
}
$idzapytania = mysqli_query($mysql, $zapytanie);
while ($wiersz = mysqli_fetch_array($idzapytania)) {
echo '$wiersz['marka']';
}
Proszę o pomoc, i z góry dziękuje