Ajax auto suggest from different tables

Hi,

I don’t know if it is the right place to post a thread on ajax. Sorry if I’m wrong!

I have this link with autosuggest ajax script.
Live demo:
http://www.dhtmlgoodies.com/scripts/ajax-dynamic-list/ajax-dynamic-list.html
Download:
http://www.dhtmlgoodies.com/scripts/ajax-dynamic-list/ajax-dynamic-list.zip

In that page the SELECT to mysql db happens in the same table.
I would to know:

If I have two mysql tables.

How I can I obtain a SELECT in the first table writing within the first input text,
and a different SELECT in the second table writing within the second input text?

Or better in the code, how I can detect from what id input text the keyword has been written and so writing a conditional code based on that id in php side? (I think this is the solution. But I am not able to do that. :()

Could you help me to comprehend where is the line in the code that explain this?

I’m trying to modify the code without succes so many times… :injured: :frowning:

I hope you can help me, please!!
many thanks really.

Depending if the tables are organized the right way, you could join them, but the best place for this question would be on SQL/MYSQL forums I guess

No. I have altready that two different tables and I don’t want to join them. I Don’t think that it’s a mysql question but a javascript and php.
The problem I think is to understand where in the code I can extract the id of the first input text and the id of the second one to create a condition in php and realize a valid ajax code.

These are the tables I have:

CREATE DATABASE IF NOT EXISTS test_db
   CHARACTER SET = latin1
   COLLATE = latin1_swedish_ci;

USE test_db;

CREATE TABLE tab_1 (
   ID_tab_1    INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
   field_tab_1 VARCHAR(255) NOT NULL,
   PRIMARY KEY (ID_tab_1)
) ENGINE = InnoDB;

CREATE TABLE tab_2 (
   ID_tab_2    INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
   field_tab_2 VARCHAR(255) NOT NULL,
   PRIMARY KEY (ID_tab_2)
) ENGINE = InnoDB;

In the code I have edited in this way in PHP side (ajax-list-countries.php):

if(isset($_GET['getCountriesByLetters']) && isset($_GET['letters'])){

     if ( (isset($_GET['id_input'])) && ($_GET['id_input'] == 'country') ) {

    	$letters = $_GET['letters'];
    	$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
    	$res = mysql_query("SELECT ID_tab_1, field_tab_1 FROM tab_1 WHERE field_tab_1 LIKE '".$letters."%'") or die(mysql_error());
    	#echo "1###select ID,countryName from ajax_countries where countryName like '".$letters."%'|";
    	while($inf = mysql_fetch_array($res)){
    		echo $inf["ID_tab_1"]."###".$inf["field_tab_1"]."|";
    	}
	
   } elseif ( (isset($_GET['id_input'])) && ($_GET['id_input'] == 'country2') ) {

    	$letters = $_GET['letters'];
    	$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
    	$res = mysql_query("SELECT ID_tab_2, field_tab_2 FROM tab_2 WHERE field_tab_2 LIKE '".$letters."%'") or die(mysql_error());
    	#echo "1###select ID,countryName from ajax_countries where countryName like '".$letters."%'|";
    	while($inf = mysql_fetch_array($res)){
    		echo $inf["ID_tab_2"]."###".$inf["field_tab_2"]."|";
    	}
	
   }

}

and edited a line (near 243) in js side in the file ajax-dynamic-list.js within the function ajax_showOptions:

var url = ajax_list_externalFile + '?' + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+") + '&id_input=' + inputObj.id;

I have added “id_input” trying to retrieve the id of the input text and then analysed that via $_GET in php side.
But without success.