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:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
|
<-----------------------START PHP SCRIPT-------------------------->
<?php
require_once('../Connections/PLT.php');
$term = $_GET['term'];
mysql_select_db($database_PLT, $PLT);
$query = "
SELECT user_id AS 'id', CONCAT(first_name, ' ', last_name) AS 'name', CONCAT(school_name, ' ', school_type) AS 'details', CONCAT(city, ', ', state) AS 'location'
FROM users
WHERE CONCAT(first_name, ' ', last_name) LIKE '$term%'
UNION
SELECT team_id AS 'id', team_name AS 'name', member_qty AS 'details', access AS 'location'
FROM teams
WHERE team_name LIKE '$term%'";
$query_result = mysql_query($query, $PLT) or die(mysql_error());
//this creates a json object
while($row = mysql_fetch_assoc($query_result))
$results[] = array('id'=>$row['id'], 'name'=>$row['name'], 'details'=>$row['details'], 'location'=>$row['location']);
if($results != NULL) {
print json_encode(array("found"=>$results));
mysql_close();
} else echo '{"found":[]}'; //must return this else you get {"found":NULL} which causes the animated gif inside the textfield to continue spinning if you enter a term that is not in the DB.
?>
<-----------------------END PHP SCRIPT--------------------------->
<-----------------------START TEST PAGE-------------------------->
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="http://www.pltproject.org/testing18/includes18/jQuery/css/plt-theme/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
<script src="http://www.pltproject.org/testing18/includes18/jQuery/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="http://www.pltproject.org/testing18/includes18/jQuery/js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#search_dialog").dialog({
//bgiframe: true,
autoOpen: false,
height: 500,
width: 500,
modal: true,
});
$("#search_button").click(function() {
$('#search_dialog').dialog('open');
var search_term = $("#search_input").val();
$.ajax({
//type: "POST",
dataType: "json",
url: "search_dialog.php",
data: {"term" : search_term},
success: function(data){
$.map(data.found, function(item) {
if(item.details >= 0 && item.details != 1){ // if is team with 0 or >1 members
return {
name: item.name,
details: item.details + ' members'
}
}
else if(item.details == 1){ // if is team with 1 member
return {
name: item.name,
details: item.details + ' member'
}
}
else
return { // if is not team
name: item.name,
details: item.details,
location: item.location
}
})
$("#dialog_cont").append("<div><div class='poster_img'></div><span class='para'><strong>" + item.name + "</strong><br>" + item.details + "<br>" + item.location + "</span></div>");
}
})
});
});
</script>
<style>
body {
background-color:#999;
}
.para {
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
float: left;
padding-top: 3px;
}
.poster_img {
float: left;
height: 48px;
width: 48px;
border: 1px solid #ddd;
background-image: url(poster_image_bkgrd.jpg);
margin-top: 5px;
margin-right: 8px;
margin-bottom: 5px;
margin-left: 5px;
z-index: 2;
}
#search_cont {
float: left;
height: 26px;
width: 345px;
margin-top: 124px;
margin-left: 30px;
background-color: #FFF;
padding-top: 2px;
padding-right: 2px;
padding-bottom: 2px;
}
#search_input {
font-family: Verdana, Geneva, sans-serif;
font-size: 100%;
outline: medium none;
color: #4a4a4a;
background-color: #FFF;
float: left;
height: 21px;
width: 313px;
border: 0 none;
padding-top: 5px;
padding-left: 5px;
}
#search_button {
float: right;
height: 26px;
width: 26px;
outline: medium none;
background-image: url(search_icon.jpg);
cursor: pointer;
overflow:hidden;
background-repeat: repeat;
background-attachment: scroll;
font-size: 0px;
border: 0px;
}
.sb_team_img {
float: left;
height: 48px;
width: 48px;
border: 1px solid #ddd;
background-image: url(bw_flag_bkgrd.jpg);
margin-top: 5px;
margin-right: 8px;
margin-bottom: 5px;
margin-left: 5px;
}
.sb_poster_img {
float: left;
height: 48px;
width: 48px;
border: 1px solid #ddd;
background-image: url(poster_image_bkgrd.jpg);
margin-top: 5px;
margin-right: 8px;
margin-bottom: 5px;
margin-left: 5px;
}
.sb_text {
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
float: left;
padding-top: 3px;
}
a.hit span.sb_text strong strong.hit {
background-color:#3B5998;
color:#fff;
}
</style>
</head>
<body>
<div id="search_cont">
<input name="search_input" type="text" id="search_input" />
<input name="search_button" type="submit" value="" id="search_button" />
</div>
<div id="search_dialog" title="search results">
<div id="dialog_cont">
NOTE: This doesn't work yet. This will be my next question
</div>
</div>
</body>
</html>
<-----------------------END TEST PAGE---------------------------->
|