1
I am trying to use jquery to make an auto complete in my search field. The connection to the bank is correct and I use the following code to save the files:
<?php
INCLUDE "conexao.php";
$sql = "SELECT * FROM consulta";
$result = mysqli_query($conexao, $sql);
$potential = mysql_fetch_array($result);
echo json_encode($potential);
?>
Using this javascript code, auto complete works:
<script>
$(function() {
var availableTags = [
"Felipe Arcaro",
"Amanda Bertollini",
"Rafael Manaus",
"Gleidson",
"Guilherme Sato",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
But using this one, no:
<script>
$(document).ready(function(){
var availableTags = <?php print(json_encode($potential)); ?>;
console.log(myArray);
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
Try replacing json_encode with JSON.stringify(json); var availableTags = <?php print(JSON.stringify($potential)); ?>;
– Eduardo Paludo
Do not mix Mysqli functions with mysql_*
– rray
Eduardo, it didn’t work. Rray, I fixed it but it seems that this was not the problem. Should I use some plugin? I was thinking of using Lect2 once I would like to create "tags" with each selection.
– Felipe