我的jquery自动完成问题与数据库无法正常工作。
我的代码
test5.php:
<?php
$wynik = mysql_query("SELECT * FROM nabk_t_item_tags")
or die('Błąd zapytania');
if(mysql_num_rows($wynik) > 0) { while($r = mysql_fetch_assoc($wynik)) {
$input = $r['tags'] ;
$fields = explode(',', $input);
foreach($fields as $field) {
echo ''.$field.'<br>'; }}}
?>
和javascript
<script type="text/javascript">
$(function() {
var availableTags = <?php include('test5.php'); ?>;
$("#tags").autocomplete({
source: availableTags,
autoFocus:true
});
});
</script>
请帮助我做错了什么?
答案 0 :(得分:0)
试试这个
<?php
$wynik = mysql_query("SELECT * FROM nabk_t_item_tags")
or die('Błąd zapytania');
if(mysql_num_rows($wynik) > 0) { while($r = mysql_fetch_assoc($wynik)) {
$input = $r['tags'] ;
$fields = explode(',', $input);
foreach($fields as $field) {
echo '"'.$field.'",'; }}}
?>
<script type="text/javascript">
$(function() {
var availableTags = [<?php include('test5.php'); ?>];
$("#tags").autocomplete({
source: availableTags,
autoFocus:true
});
});
</script>