PDA

View Full Version : question about an autocomplete example



zjnbshifox
22 Jun 2007, 3:27 AM
I build an example of autocomplete.Javascript code is no problem.
But i can't get the parameter in my php file


/**
* @author Administrator
*/
Ext.onReady(function(){
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'readno.php'
}),
reader: new Ext.data.JsonReader({
root: 'topics',
totalProperty: 'totalCount',
id: 'sid',
}, [
{name: 'stud_no', mapping: 'stud_no'},
{name: 'sid', mapping: 'sid'},
{name: 'stud_name', mapping: 'stud_name'}
])
});

// Custom rendering Template
var resultTpl = new Ext.Template(
'<div>',
'<h3><span>{stud_no}</span></h3>',
'</div>'
);

var search = new Ext.form.ComboBox({
store: ds,
displayField:'stud_no',
typeAhead: false,
minChars: 1,
loadingText: 'Searching...',
width: 570,
pageSize:10,
hideTrigger:true,
tpl: resultTpl,
});
// apply it to the exsting input element
search.applyTo('search');

});
and the readno.php code is like this:


<?php
include("DataBase.php");
header('Content-type: application/json');
$db = new DataBase();
$n = $_POST["search"];
$rs = $db->executeQuery("select id as sid,num as stud_no,name as stud_name from stud where num like '${n}%'");
$result = array();
$result["totalCount"] = "".count($rs);
$result["topics"] = $rs;
echo json_encode($result);
?>

The question is how can i get the parameter

liggett78
22 Jun 2007, 3:36 AM
http://www.extjs.com/deploy/ext/docs/output/Ext.form.ComboBox.html#config-queryParam. Investigate what is send to the server and use this param in your PHP-code or replace it with your own.
On the other note: you probably don't want to use the value unverified, it's the classical case of SQL injection.

zjnbshifox
22 Jun 2007, 4:58 PM
Thank you very much.
And there is another question. If I have more than 10 smilar numbers,the how can I get the parameter of page?

And thank you for your notice of SQL injection,I will pay attention to it.:)