php autocompletion query mysql
Posté : 19 juin 2012, 15:56
Bonjour,
J'ai un problème dans un script jquery d'autocompletion, voici le code :
Dans ce code, seul le prénom est appelé, et est affiché dans les résultats. Mais je n'ai pas trouvé comment afficher le nom de famille.
Si quelqu'un sait comment faire, je ne dit pas non
Merci
J'ai un problème dans un script jquery d'autocompletion, voici le code :
Dans ce code, seul le prénom est appelé, et est affiché dans les résultats. Mais je n'ai pas trouvé comment afficher le nom de famille.
Si quelqu'un sait comment faire, je ne dit pas non
Merci
// PHP5 Implementation - uses MySQLi.
// mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase');
$db = new mysqli('...', '...', '...', '...');
if(!$db) {
// Show error if we cannot connect.
echo 'Erreur : Impossible de se connecter à la base';
} else {
// Is there a posted query string?
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
$query = $db->query("SELECT prenom, nom FROM wa_communaute WHERE prenom LIKE '%" . $queryString . "%' ORDER BY prenom LIMIT 8");
if($query) {
// While there are results loop through them - fetching an Object.
// Store the category id
$catid = 0;
while ($result = $query ->fetch_object()) {
if($result->cat_id != $catid) { // check if the category changed
echo '<span class="category">'.$result->cat_name.'</span>';
$catid = $result->cat_id;
}
echo '<a href="'.$result->url.'">';
echo '<img src="search_images/'.$result->img.'" alt="" />';
$prenom = $result->prenom;
if(strlen($prenom) > 35) {
$prenom = substr($prenom, 0, 35) . "...";
}
echo '<span class="searchheading">'.$prenom.' </span>';
$description = $result->desc;
if(strlen($description) > 80) {
$description = substr($description, 0, 80) . "...";
}
echo '<span>'.$description.'</span></a>';
}
echo '<span class="seperator"><a href="http://www.marcofolio.net/sitemap.html" title="Sitemap">Nothing interesting here? Try the sitemap.</a></span><br class="break" />';
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
}