-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax-search.php
56 lines (55 loc) · 1.62 KB
/
ajax-search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require_once("controller.php");
require_once("modelDAO.php");
if(isset($_GET['keyword'])){
$keyword = trim($_GET['keyword']) ;
$keyword = mysql_real_escape_string($keyword);
$keyword = htmlspecialchars($keyword);
if(isset($_GET['sur'])){
$pseudo = $_SESSION['login'];
$m = getMembreByLogin($pseudo);
$id = $m->id();
$query = "select * from listes_public where titre like '%$keyword%' and id_membre = '$id'";
}
else{
$query = "select * from listes_public where titre like '%$keyword%'";
}
$result = mysql_query($query);
if(mysql_num_rows($result) != 0){
$arr = array();
$i = 0;
while($result1 = mysql_fetch_array($result)){
$arr[$i]['id'] = $result1['id'];
$arr[$i]['titre'] = $result1['titre'];
$arr[$i]['mots'] = $result1['liste'];
$arr[$i]['categorie'] = $result1['categorie'];
$arr[$i]['categorie2'] = $result1['categorie2'];
$i++;
}
echo json_encode($arr);
}else {
echo 'No Results for :"'.$_GET['keyword'].'"';
}
}elseif(isset($_GET['groupe'])){
$g_keyword = trim($_GET['groupe']) ;
$g_keyword = mysql_real_escape_string($g_keyword);
$g_keyword = htmlspecialchars($g_keyword);
$query = "select * from groupe where nom like '%$g_keyword%'";
$result = mysql_query($query);
if(mysql_num_rows($result) != 0){
$arr = array();
$i = 0;
while($result1 = mysql_fetch_array($result)){
$arr[$i]['id'] = $result1['id'];
$arr[$i]['nom'] = $result1['nom'];
$arr[$i]['date'] = $result1['date'];
$i++;
}
echo json_encode($arr);
}else {
echo 'No Results for :"'.$_GET['groupe'].'"';
}
}else {
echo 'Parameter Missing';
}
?>