Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Autocomplete problem

More
10 years 4 weeks ago #141382 by darioc
Autocomplete problem was created by darioc
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 ?
The topic has been locked.
More
10 years 3 weeks ago #141429 by jelo
Replied by jelo on topic Autocomplete problem

darioc wrote: Any Idea ?


You're talking about this workaround?
www.limesurvey.org/manual/Workarounds:_M...wers_for_text_inputs

Are you using a Limesurvey version/build which is compatible for the workaround?
I don't see any hint that the workaround works with LS 2.5.X.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
More
10 years 3 weeks ago #141430 by darioc
Replied by darioc on topic Autocomplete problem
Yes that workaround.

My version of LM is 2.50+ Build 160620

The workaround talk about "Update for LimeSurvey 2.05+".
The topic has been locked.
More
10 years 3 weeks ago #141522 by darioc
Replied by darioc on topic Autocomplete problem
Someone can point me how to debug the autocomplete.php?
The topic has been locked.
More
10 years 3 weeks ago #141524 by jelo
Replied by jelo on topic Autocomplete problem
Since most workarounds for LS 2.05+ are not compatible with LS 2.50+ you're are looking for a new workaround.

You already have hard-coded some lines:
$query = "SELECT * FROM table_name WHERE column_name LIKE :term";

Why did you replace table_name with a hardcoded value?
$query = "SELECT * FROM answers_q_778314 WHERE answers LIKE :term";

I don't know who has provided that workaround. IMHO this should be a feature of LS. Such workarounds break too often.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
More
10 years 3 weeks ago #141526 by darioc
Replied by darioc on topic Autocomplete problem

jelo wrote: Since most workarounds for LS 2.05+ are not compatible with LS 2.50+ you're are looking for a new workaround.

You already have hard-coded some lines:
$query = "SELECT * FROM table_name WHERE column_name LIKE :term";

Why did you replace table_name with a hardcoded value?
$query = "SELECT * FROM answers_q_778314 WHERE answers LIKE :term";

I don't know who has provided that workaround. IMHO this should be a feature of LS. Such workarounds break too often.


I've replaced table_name and column_name because I don't know where to specify the table and the column for extract the data.
when I read the workaround I don't understend where I can specify the table and columns.... you ?
The topic has been locked.
More
10 years 3 weeks ago #141530 by jelo
Replied by jelo on topic Autocomplete problem
Did you try the workaround without your modification. I thought that the vars are already defined.
I have found the creator of the workaround:
www.limesurvey.org/forum/can-i-do-this-w...-mysql-in-limesurvey ?

Perhaps you can get in touch with the creator.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose