简体   繁体   中英

jquery tokeninput very slow

I am using Jquery TokenInput with php 5.5.8. 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)

This is my code which generate the json for me after making the search

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

    $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.

So replace localhost with 127.0.0.1 in your config file.

Also, if you are using Php 5.5, why don't you use json_encode instead of creating manually your json. Your way of generating json manually might also be generating an error along the road.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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