Character problem with AutoComplete plugin

Character problem with AutoComplete plugin

menhirmenhir Posts: 3Questions: 1Answers: 0

Hi,

I am trying to get values for AutoComplete plugin from MySql db. It works excellent when only standard characters are used, but if search string or search result contains special characters like å, ä, ö I get a NULL-value. I have tried to specify charset on several places without result and hope some of you have a solution. It can't be first time this problem has to be solved.

My last post disappeared when I tried to save it because text was too long so here are a short version of the most important code.

The header for the page showing datatables table/editor is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Tentamensadministration</title>

        <link rel="stylesheet" type="text/css" href="css/demo.css">
       
        <link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.7/css/jquery.dataTables.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/tabletools/2.2.4/css/dataTables.tableTools.css">
        <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css">
        <link rel="stylesheet" type="text/css" href="css/dataTables.editor.css">

        <script type="text/javascript" charset="utf-8" src="https://code.jquery.com/jquery-1.11.2.js"></script>
        <script type="text/javascript" language="javascript" src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/tabletools/2.2.4/js/dataTables.tableTools.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/dataTables.editor.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/table.tentamina.js"></script>
        <script type="text/javascript" language="javascript" src="js/editor.autoComplete.js"></script>
        
    </head>

The important part of table.tentamina.js is:

            {
                "label": "Kurs",
                "name": "course",
                "type": "autoComplete",
                "opts": {
                    "source": "kursnamn.php",
                    minLength: 2
                }
            },

File kursnamn.php searching in the db is (without db connection details):

try {
  $conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch(PDOException $e) {
    echo $e->getMessage();
}

$return_arr = array();
 
if ($conn)
{
    $ac_term = "%".$_GET['term']."%";
    $query = "SELECT kurs FROM tentamina_kurser where kurs like :term";
    $result = $conn->prepare($query);
    $result->bindValue(":term",$ac_term);
    $result->execute();
     
    /* Retrieve and store in array the results of the query.*/  
    while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
        //echo $row['kurs'] . "<br>";
        $row_array['value'] = $row['kurs'];  //utf8_encode($row['kurs']);
        
        array_push($return_arr,$row_array);
        
    }
 
     
}
/* Free connection resources. */
$conn = null; 
/* Toss back results as json encoded array. */
echo json_encode($return_arr);

Replies

  • ladokjohanladokjohan Posts: 15Questions: 3Answers: 0

    By the way, I have bought the editor for this username if it matters. Sorry I posted last post with my old username.

This discussion has been closed.