- Posts: 15
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<?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); ?>
<?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); } }
<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>
darioc wrote: Any Idea ?
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.