I have a html search bar like so:
<form id="testblah" action="search_results.php" method="GET">
<input type="text" name="search" class="Search_bar_box" id="search">
</form>
I am then using Jquery to auto complete the input of a search criteria using pre-defined tags like so:
<script>
$(function() {
$('form').each(function() {
$(this).find('input').keypress(function(e) {
// Enter pressed?
if(e.which == 10 || e.which == 13) {
this.form.submit();
}
});
});
});
$(function () {
var availableTags = [
"Telehandlers",
"Cranes",
"Fork Attachments",
"Aggreko",
"12 Tonne Telhandlers",
"Marwood",
"Crane Suppliers in Manchester",
"Total",
"Oil, Gas & Lubricants",
"Tomato Plant"
];
$("#search").autocomplete({
source: availableTags,
select: function (event, ui) {
window.location = 'search_results.php?search=' + ui.item.value;
}
});
$('#searchForm').on("submit", function (event) {
event.preventDefault();
alert($('#search').val());
});
});
</script>
This all works fine, however, what I want to do now is change my tags from pre-defined text so that my tags are instead pulled from my MySQL data. so I am trying to run a MySQL query to get all data from my table like so:
<?php $query12 = "SELECT * FROM supplier_users, supplier_stats GROUP BY supplier_users.user_id";
$result12 = mysql_query($query12);
while($row1 = mysql_fetch_assoc($result12)) {
$tags = $row1; } ?>
and then trying to place my string inside the jquery tags section like so:
$(function () {
var data = "<?= $tags ?>";
var availableTags = [
data ];
however this stops my jquery from working. Can someone please show me where I am going wrong and how I would need to do this. thanks in advance