I've set up an AJAX autocomplete using jQuery. Currently this looks up the info from a php script (below) the array is entered directly in the PHP script - it works but is not ideal.
Code: Select all
<?php
$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array(
"Quentin <em>Tarantino</em>"=>"1",
"Christopher <em>Nolan</em>"=>"2",
"Joel <em>Coen</em>"=>"3",
"Ethan <em>Coen</em>"=>"4"
);
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
echo "$key|$value\n";
}
}
?>Code: Select all
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT first_names, surname, id FROM writers";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Name :{$row['first_names']} <br>" .
"Surname : {$row['surname']} <br>" .
"ID : {$row['id']} <br><br>";
}
include 'closedb.php';
?>Here is my latest non functioning attempt...
Code: Select all
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT first_names, surname, id FROM writers";
$result = mysql_query($query);
if (!$query) return;
while($items = array(
"{$row['first_names']}"."{$row['surname']}"=>"{$row['id']}",
));
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $query) !== false) {
echo "$key|$value\n";
}
include 'closedb.php';
}I really don't have enough experience to know if I'm just a small syntax wrong or are completely out of the ballpark.
If anyone spots an obvious mistake (or 2 or probably more!) I'd really appreciate the help/feedback.
Many thanks in advance