简体   繁体   English

jQuery tokeninput非常慢

[英]jquery tokeninput very slow

I am using Jquery TokenInput with php 5.5.8. 我在php 5.5.8中使用Jquery TokenInput。 I take query from my database but it is very slow. 我从数据库中查询,但速度很慢。 Before it will display a result, it takes some time. 在显示结果之前,需要一些时间。 I have only few informations in my database (2 line) 我的数据库中只有很少的信息(2行)

This is my code which generate the json for me after making the search 这是我的代码,在搜索后为我生成json

This is my code that i use to make the search. 这是我用来进行搜索的代码。 I don't know why it is so slow 我不知道为什么这么慢

<?php
session_start(); 
# Connect to the database

require('fonctions.php');
require('configurations.php');
//require('encodage.php');


$q=addslashes($_REQUEST['q']);

$q =mysqli_real_escape_string($connection, $q);



//On effectue une opération que si on a mis au moins 1 caractere
$notre_tableau=explode(',',$q);


$compter_tableau=count($notre_tableau);

$username =  $_SESSION['username'];
$id_super_admin = $_SESSION['id_super_admin'];


//On recupere là où l'id super admin est egale a l'id du super admin

$req_search = "SELECT id_ojm_peoples, nom, prenom, countrycode, id_city  

FROM  ojm_peoples

WHERE id_super_admin='$id_super_admin' AND  ";

##########################################################################################


for ($i = 0; $i < $compter_tableau; $i++) 
{
$notremotchercher=trim($notre_tableau["$i"]);


if($i==$compter_tableau) { $liaison="AND"; } else { $liaison=""; }

if($i!=0) { $debutliaison="AND"; } else { $debutliaison=""; }

//On n'effectue la recherche que si c'est un truc non vide

if($notremotchercher!='')
{
$req_search .= "$debutliaison (nom LIKE '%$notremotchercher%' OR prenom LIKE '%$notremotchercher%')  $liaison";
}
/////////////////////
/////////////////////

}
##########################################################################################


############
//echo "$req_search<br><br>";
# Perform the query


if($q!='')
{
    $requete=mysqli_query($connection, "$req_search LIMIT 20") or die(mysqli_error($connection));



    $tableau=array();

    $tableau_valeur=array();



    # Collect the results
    while($affichage = mysqli_fetch_assoc($requete)) 
    {
    $id_ojm_peoples =  $affichage ['id_ojm_peoples'];
    $nom =  stripslashes($affichage ['nom']);
    $prenom =  stripslashes($affichage ['prenom']);

    $countrycode =  stripslashes($affichage ['countrycode']);
    $id_city =  $affichage ['id_city'];

    $nom_pays = nom_pays($countrycode, 'Name');

    $nom_ville = nom_ville($id_city, '/');

############################################################################
    //On recupere l'url de l'image de cette eglise
    $select = mysqli_query($connection, "SELECT url_avantar FROM ojm_avantar WHERE 

id_super_admin='$id_super_admin' AND id_ojm_peoples='$id_ojm_peoples'  AND is_main='Oui' LIMIT 1") or die(mysqli_error($select));

    $prenons = mysqli_fetch_assoc($select);

    mysqli_free_result($select);

    $url_image_article = $prenons['url_avantar'];




        if($url_image_article!='')
        {
        $mettre_debut = "<img src='phpthumb/phpThumb.php?src=

$url_image_article&w=80&fltr[]=ric|50|20&f=png' align='middle' border='0'>";
        }
        else
        {
        $mettre_debut = "<img src=images/nobody.png width=20>";
        }
##########################################################################################

##      

    $nom_prenom="$nom $prenom ";


    $a_mettre="$mettre_debut $nom_prenom <br/><span class='actuelle'>$nom_ville / $nom_pays</span> ";


        array_push($tableau,$a_mettre);

        array_push($tableau_valeur,$id_ojm_peoples);



    }

    mysqli_free_result($requete);

    $compter = count($tableau);

//echo $req_search;

//echo "<h1>$compter</h1>"; 
    //Debut de l'affichage de la forme Json 
    echo '[';


    //On utilise notre boucle for pour generer ce qu'il faut pour affiche le tableau
    $suite=',';
    for($i=0;$i<$compter;$i++)
    {

    if($i==($compter-1)) { $suite='';  }

    $valeur_tableau = $tableau_valeur["$i"];

    $valeur_tableau_i = $tableau["$i"];

    //echo "{\"id\":\"",$tableau_valeur["$i"],"\", \"name\":\"",$tableau["$i"],"\"}$suite ";



    echo "{\"id\":\"$valeur_tableau\", \"name\":\"$valeur_tableau_i\"}$suite ";

    }
    //Fin de l'affichage de la forme Json 
    echo ']';
}
//Fin du cas ou le mot rechercher n'est pas vide

mysqli_close($connection);


?>

And this is my configurations.php code 这是我的configuration.php代码

    $mysqlport = @getenv('S2G_MYSQL_PORT');

    $mysqlhost = "localhost:".@$mysqlport;

    //Le host recuperé du formulaire
    $mysql_host='localhost';

    $root = 'root';
    $dbpassword ='';    

    $db = 'johnmax';

/*Si le port mysql ne donne rien, on donne la valeur donne par defaut emise par le formulaire*/

    if (@$mysqlport=="") 
    {

        $mysqlhost = $mysql_host;
    }

/////////////////// 





    $connection=mysqli_connect($mysqlhost,  $root, $dbpassword, $db) or die(mysqli_connect_error($connection)); 

Everything looks normal in your code. 在您的代码中,一切看起来都很正常。 I had faced something similar in the past and in my case it was due to the fact that I was in local and I was using localhost as host of the server instead of 127.0.0.1 while using easyphp. 我过去曾经遇到过类似的情况,在我的情况下,这是由于我在本地,并且在使用easyphp时使用localhost作为服务器的主机,而不是127.0.0.1

So replace localhost with 127.0.0.1 in your config file. 因此,在配置文件中将localhost替换为127.0.0.1

Also, if you are using Php 5.5, why don't you use json_encode instead of creating manually your json. 另外,如果您使用的是Php 5.5,为什么不使用json_encode而不是手动创建json。 Your way of generating json manually might also be generating an error along the road. 您手动生成json的方式也可能会沿途生成错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM