sassenach 0 Junior Poster in Training

hi,

I am using a live search snippet from "http://www.dynamicajax.com/fr/Suggest_Frontend-271_290_312_313.html".
I started connecting it to my code, but i need help with expanding the search.
It currently only searches for one field in the DB, but i want it to search more than one field from a table in the DB.

This is my code.
My form (in page jobs.php):

form id="frmSearch" action="/jobs.php?'.get_url(1).'">
					<input type="text" id="txtSearch" name="txtSearch" alt="Search Criteria" onkeyup="searchSuggest();" autocomplete="off" />
					<input type="submit" id="cmdSearch" name="cmdSearch" value="Search" alt="Run Search" />
					<div id="search_suggest"></div>
				</form><br/><br/>

The JS page (ajax_search.js):

/*
	This is the JavaScript file for the AJAX Suggest Tutorial

	You may use this code in your own projects as long as this 
	copyright is left	in place.  All code is provided AS-IS.
	This code is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	For the rest of the code visit http://www.DynamicAJAX.com
	
	Copyright 2006 Ryan Smith / 345 Technical / 345 Group.	

*/
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}

//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();

//Called from keyup on the search textbox.
//Starts the AJAX request.
function searchSuggest() {
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {
		var str = escape(document.getElementById('txtSearch').value);
		searchReq.open("GET", '/searchSuggest.php?search=' + str, true);
		searchReq.onreadystatechange = handleSearchSuggest; 
		searchReq.send(null);
	}		
}

//Called when the AJAX response is returned.
function handleSearchSuggest() {
	if (searchReq.readyState == 4) {
		var ss = document.getElementById('search_suggest')
		ss.innerHTML = '';
		var str = searchReq.responseText.split("\n");
		for(i=0; i < str.length - 1; i++) {
			//Build our element string.  This is cleaner using the DOM, but
			//IE doesn't support dynamically added attributes.
			var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
			suggest += 'onmouseout="javascript:suggestOut(this);" ';
			suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
			suggest += 'class="suggest_link">' + str[i] + '</div>';
			ss.innerHTML += suggest;
		}
	}
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}
//Click function
function setSearch(value) {
	document.getElementById('txtSearch').value = value;
	document.getElementById('search_suggest').innerHTML = '';
}

The PHP page that gets records from the DB (searchSuggest.php):

if (isset($_GET['search']) && $_GET['search'] != '') {
	//Add slashes to any quotes to avoid SQL problems.
	$search = addslashes($_GET['search']);
	//Get every page title for the site.
	$suggest_query = mysql_query("SELECT distinct(job_id) as job_id FROM job_item WHERE job_id like('" . 
		$search . "%') ORDER BY job_id") or trigger_error("Query: $suggest_query\n<br />MySQL Error: " .mysql_error());			
	while ($suggest = mysql_fetch_array($suggest_query, MYSQL_ASSOC)) {	
	//while($suggest = db_fetch_array($suggest_query)) {
		//Return each page title seperated by a newline.
		echo $suggest['job_id'] . "\n";
	}
}

I make the connection to the DB above the page. That works perfectly.

So how do I change the "SELECT" query so that when I input something in the search box, it will search more than one field in the table in the DB?

Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.