* * code mis à jour à partir de 3-28nest pas cette ajax recherche en direct travaillant
index.php
<!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>
<title>jQuery Search Demonstration</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".keywords").keyup(function(){
$('#key').html($(this).val());
$('#table').html($('.table:checked').val());
// Do the ajax call
// Get the textbox value: $(this).val()
// Get the radio value: $('.table:checked').val()
/*$.post("search.php", { keywords: $(".keywords").val() }, function(data){
$("div#content").empty()
$.each(data, function(){
$("div#content").append("- <a href='prof.php?pID=" + this.pID + "'>" + this.last + "</a>");
});
}, "json");*/
});
});
</script>
</head>
<body>
Search by:
<input type="radio" name="table" class="table" value="Table 1" />Professor<br />
<input type="radio" name="table" class="table" value="Table 2" />Department<br />
<input type="radio" name="table" class="table" value="Table 3" />Course<br />
<input type="text" name="search" class="keywords">
<input type="submit" name="submit" class="search">
<div id="content">
</div>
</body>
</html>
search.php
<?php
$link = mysql_connect('##',"##","##");
mysql_select_db("###", $link);
$keywords = mysql_real_escape_string($_POST["keywords"]);
$query = mysql_query("SELECT pID, lname, fname
FROM Professor
WHERE CONCAT(lname,fname) LIKE '%". $keywords . "%'");
$arr = array();
while($row = mysql_fetch_array ($query))
{
$arr[] = array("pID" => $row["pID"], "last" => $row["lname"], "first" => $row["fname "]);
}
echo json_encode($arr);
?>
Sql pour chaque sélection: [Professeur]
SELECT pID, lname, fname
FROM Professor
WHERE CONCAT(lname,fname) LIKE '%". $keywords . "%'";
[Département]
SELECT prefix, code
FROM Department
WHERE name LIKE '%". $keywords . "%'";
[cours]
préfixe SELECT, le code du parcours OÙ CONCAT (préfixe, bien sûr) LIKE « % ». $ keywords "% '";
-vous obtenez un message d'erreur? Avez-vous des résultats de search.php? – Prisoner
votre requête va échouer, singe citation aucune citation de fin correspondant, les mots-clés LIKE ne fonctionneront pas pour plusieurs mots ... –
Dagon, en ajoutant une seule citation ne fait rien. Je l'ai juste essayé. Vous parlez comme '% **' ** "right? – Jshee