Hi all,
I am making a flight search engine where i am trying to create a autocomplete textbox. I mean when a user starts typing in the textbox, it will show all related data from my database table.
I am new to programming and therefore I have adopt a code from online but it doesn't work, I don't know why. Can anyone please help?
If you know any other easy way of doing it, please tell me also
This is my Javascript code:
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<script type="text/javascript">
$().ready(function() {
$("#depAirport").autocomplete("autoCompleteMain.php", {
width: 260,
matchContains: true,
//mustMatch: true,
//minChars: 0,
//multiple: true,
//highlight: false,
//multipleSeparator: ",",
selectFirst: false
});
});
</script>
<form>
<label for="depAirport">Deperture airport</label>
<input type="text" id="depAirport" name="depAirport" placeholder="Type destination airport" required autofocus>
</form>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="airline_database"; // Database name
$con = mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db_name, $con) or die(mysql_error());
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select DISTINCT departure_airport as departure_airport from depAirport where departure_airport LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$cname = $rs['departure_airport'];
echo "$cname\n";
}
?>
PLEASE HELP ASAP