Hi at all,
i've followed the manual to got the autocomplete, but something don't work, can someone check this configuration:
autocomplete.php
Code:
<?php
// Include files outside of webroot
set_include_path('/var/www/limesurvey/test-survey');
// Fetch database credentials
require_once ('constant.php');
// Connect to database and perform query
require_once ('database.php');
// Clear query
$db = null;
// Encode results in JSON. This is required for jquery autocomplete
echo json_encode($return_arr);
?>
database.php
Code:
<?php
// Connect and query MySQL database, using PDO
try {
$db = new PDO(DB_DRIVER . ":dbname=" . DB_DATABASE . ";host=" . DB_SERVER . ";charset=utf8", DB_USER, DB_PASSWORD);
}
catch(PDOException $e) {
echo $e->getMessage();
}
$return_arr = array();
if ($db)
{
$ac_term = "%".$_GET['term']."%";
$query = "SELECT * FROM answers_q_778314 WHERE answers LIKE :term";
$result = $db->prepare($query);
$result->bindValue(":term",$ac_term);
$result->execute();
// Fetch data and store in array
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$row_array['label'] = $row['answers'];
$row_array['value'] = $row['answers'];
array_push($return_arr,$row_array);
}
}
simple test on command line :
root@survey www/limesurvey# php autocomplete.php
PHP Notice: Undefined index: term in /var/www/limesurvey/test-survey/database.php on line 16
[{"label":"ciao","value":"ciao"},{"label":"test1","value":"test1"},{"label":"test2","value":"test2"},{"label":"test3","value":"test3"},{"label":"ciao1","value":"ciao1"},{"label":"ciao3","value":"ciao3"}]
the connection to the database work, but on the question don't appaer nothing.
Here the code inside the question :
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var qID = 78;
$('#question'+qID+' input[type="text"]').autocomplete({
minLength: 1,
source: 'survey/autocomplete.php'
});
});
</script>
Any Idea ?