My original query is taking a term from text field and start searching for it in two columns of one table [in order in create an autocomplete]
$query = $_GET['query'];
$sql ="SELECT f_name, l_name FROM student WHERE (f_name ILIKE '%$query%' OR l_name ILIKE '%$query%');
$result = pg_query($con, $sql);
while ($row = pg_fetch_array($result))
{
$names[] = array('f_name' => $row[0], 'l_name' => $row[1]);
}
$name_list = array();
$name_list['success'] = true;
$name_list['names'] = $names;
$name_list['totalCount'] = count( $name_list['names'] );
echo json_encode($name_list);
No I want to add an extra criteria from another table (e.g: subject), So the user can enter a part of students first name, last name or subject. also I need to know the type of returned value, I mean if this is a name or a subject. so i can show a small icon depending on the type.
This is the model so you can imagine how I am doing it:
Ext.define("Post", {
extend: 'Ext.data.Model',
proxy: {
type: 'ajax',
url: 'app/search.php',
reader: {
type: 'json',
root: 'names',
autoLoad: true,
totalProperty: 'totalCount'
}
},
fields: ['f_name','l_name'
, {
name : 'display',
convert : function(v, rec) {
return rec.get('f_name') + ',' + rec.get('l_name');
}
}
]
});
So if user entered: mat the result would be:
Mathio,Jay << student's first and last name
Mark,Matt << student's first and last name
After my changes it should be like:
Mathio,Jay << student's first and last name
Mark,Matt << student's first and last name
Mathematics << subject