Question : jQuery Autocomplete with PHP / MySQL [PART 4 continued...]

( I am splitting my questions up in parts so that you can get 1000’s of points versus just 500.  Each question will build upon the previous one so make sure you look for [PART 6] and beyond after you figure this one out.)

[PART 4 continued...] – jQuery Autocomplete Suggestion Box CSS term highlights

Hielo, where you at dude?  I found another problem when I tried to change the configuration a bit. I need to change my SQL from this:


SELECT first_name, last_name, co_name
FROM users
WHERE first_name LIKE '$term%'
OR last_name LIKE '$term%'
OR CONCAT(first_name, ' ', last_name) LIKE '$term%'


...to this:


SELECT CONCAT(first_name, ' ', last_name) AS 'name' co_name
FROM users
WHERE first_name LIKE '$term%'
OR last_name LIKE '$term%'
OR CONCAT(first_name, ' ', last_name) LIKE '$term%'
UNION
SELECT co_name AS 'name'
FROM companies
WHERE co_name LIKE '$term%'


...so that I can 'UNION' companies into my query.  The problem is that  I can't use your last fix because it relies on first_name and last_name being separate to highlight properly.  However, I need to combine them AS 'name' in order to 'UNION' in companies because it there is only one company name.

Anyway, can you alter the var on line 15 so that it will highlight the 'term' letters at the beginning of the first and last names by determining where the space is between them?  This way, I can combine them both as 'name' and not lose the highlight on the last name.

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:
<script type="text/javascript">
	$(function() {
		$("#send_to").autocomplete({
			source: function(request, response) {
				$.ajax({
					url: "find_ships.php",
					dataType: "json",
					data: {
						//featureClass: "P",
						//style: "full",
						//maxRows: 10,
						term: request.term
					},
					success: function(data) {
						var re=new RegExp('^('+request.term+')(.*)','i');
						
						response($.map(data.users, function(item) {
							
							return {
								label: item.first_name.replace( re, "<strong class='hit'>$1</strong>$2") + " " + item.last_name.replace( re, "<strong class='hit'>$1</strong>$2"),
								value: item.first_name + " " + item.last_name,
								company: item.co_name
							}
						}))
					}
				})
			},
			minLength: 1,
			focus: function(event, ui) {
				$('#send_to').val(ui.item.label.replace(/[<][^>]+>/g,''));
				return false;
			},
			select: function(event, ui) {
				$('#send_to').val(ui.item.label.replace(/[<][^>]+>/g,''));
				//$('#project-id').val(ui.item.value);
				//$('#project-description').html(ui.item.desc);
				//$('#project-icon').attr('src', '../images/' + ui.item.icon);
				
				return false;
			}
		})
		.data( "autocomplete" )._renderItem = function( ul, item ) {

			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a class='hit' style='float: left;'><div><div class='poster_img'></div><span class='para'><strong>" + item.label + "</strong><br>" + item.company + "</span></div></a>" )
				.appendTo( ul );
		};
	});
	</script>

Answer : jQuery Autocomplete with PHP / MySQL [PART 4 continued...]

Sorry to waste your time.  It turns out I was not typing in the correct URL.  I mean I wasn't adding /owa or /exchange to the end.  This behaviour is expected.  I didn't realize.  This article explains it: http://blogs.technet.com/b/isablog/archive/2008/04/29/troubleshooting-owa-2007-publishing-rules-on-isa-server-2006.aspx.  I don't know why that was so hard to figure it.  Anyway thanks for your help.
Random Solutions  
 
programming4us programming4us