MySQL Forums
Forum List  »  Newbie

Re: Auto Complete
Posted by: Bruce Nickles
Date: March 15, 2016 07:23AM

Ok I have devolped a code but it still displays all artists from a-z when you type in a letter and i want it to display only the artist names that start with the letter you type in here is my code how would i modify/change it to do what i want it to do:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>;
<script>
//$(function() {
// $("#artistList").change(function () {
// var artistValue = $("#artistList option:selected" ).text();
// window.location.replace("/samphp/web/playlist.php?q="+artistValue);
// }
//});
function GoToArtist() {
artistValue = $("#artistList").val();
window.location.replace("/samphp/web/playlist.php?search="+artistValue);
}
</script>

<?php
$servername = "localhost";
$username = "alloldie_samdb";
$password = "Hockey26!";
$dbname = "alloldie_samdb";

echo "<select name='artist' id='artistList' onchange='GoToArtist()' style='padding: 5px;'><option>Artist Quick Search</option>";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT DISTINCT artist FROM songlist ORDER BY artist");
$stmt->execute();

// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach($stmt->fetchAll() as $k=>$v) {
//echo $v[] = $v;
echo "<option value='".implode($v)."'>".implode($v)."</option>";
//echo $data[] = $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</option>";
?>

Options: ReplyQuote


Subject
Written By
Posted
March 12, 2016 11:44AM
March 12, 2016 12:07PM
March 12, 2016 12:44PM
March 12, 2016 01:19PM
Re: Auto Complete
March 15, 2016 07:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.