16/02/2011, 13:33:40
Ok, alors changement de stratégie
J'ai trouvé un script d'autocompletion jquery. Cependant, encore un autre soucis de je ne sais où.
Voila mon code du head :
[ins]
<script type="text/javascript" src="js/autocompletion/jquery.js"></script>
{literal}<script type="text/javascript">
$.noConflict();[/ins]
[ins] function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post({global_content name='autocompletion'}, {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
</script>{/literal}
[/ins]
Normalement le code que j'ai mis en rouge link vers une page php en fait "autocompletion.php" qui "include" d'autres pages php. J'ai essayer de mettre le tout dans un global content comme ci-dessus. J'ai pas d'erreur js Est-ce la bonne méthode à employer? En tout cas ,ça ne marche pas dans une balise utilisateur.
Voici le code autocompletion.php à tout hasard
[ins]
function transform_specialchars(&$table){
if(is_array($table))
while(list($key, $value) = each($table))
if(is_array($table[$key]))
transform_specialchars($table[$key]);
else
$table[$key] = &htmlspecialchars($value);
else
$table = &htmlspecialchars($table);
}[/ins]
[ins]function mysql_DateTime($d) { [/ins]
[ins] $date = substr($d,8,2)."-"; // jour
$date = $date.substr($d,5,2)."-"; // mois
$date = $date.substr($d,0,4); // ann馥
return $date;
} [/ins]
[ins]// Description: mySQL4.1 (mySQL)
class db {
var $link=0;
var $num_queries=0;
var $query_result;
function db($db_host,$db_user,$db_pass,$db_name) {
$this->link = mysql_connect($db_host,$db_user,$db_pass,true);
@mysql_select_db($db_name,$this->link);
}[/ins]
[ins] function sql_close(){
if($this->link)
return mysql_close($this->link);
else
return false;
}[/ins]
[ins] function sql_query($query){
unset($this->query_result);
$this->num_queries++;
$this->query_result = mysql_query($query, $this->link);
if($this->query_result)
return $this->query_result;
else
return false;
}[/ins]
[ins] function sql_numrows($query_id=0){
if(!$query_id)
$query_id=$this->query_result;
return ($query_id)?mysql_num_rows($query_id):false;
}[/ins]
[ins] function sql_affected(){
return ($this->link)?mysql_affected_rows($this->link):false;
}[/ins]
[ins] function sql_dataseek($query_id=0, $num_row){
if(!$query_id)
$query_id = $this->query_result;[/ins]
[ins] if($query_id)
return mysql_data_seek($query_id,$num_row);
else
return false;
}[/ins]
[ins] function sql_fetchrow($query_id=0,$special=true)
{
if(!$query_id)
$query_id = $this->query_result;[/ins]
[ins] if($query_id){
$result = mysql_fetch_array($query_id, MYSQL_ASSOC);
if($special==true)
transform_specialchars($result);
return $result;
}
else
return false;
}[/ins]
[ins] function sql_fetchrowset($query_id=0,$special=true)
{
if(!$query_id)
$query_id = $this->query_result;[/ins]
[ins] if($query_id){
$temp = 0;
$result = array();
$this->sql_dataseek($query_id, 0);
while($temp = mysql_fetch_array($query_id, MYSQL_ASSOC))
$result[] = $temp;
if($special==true)
transform_specialchars($result);
$this->sql_dataseek($query_id, 0);
return $result;
}
else
return false;
}[/ins]
[ins] function sql_insertid(){
return ($this->link)?mysql_insert_id($this->link):false;
}[/ins]
[ins] function sql_listtables($db_name){
$tables_list = array();
$temp_result = mysql_list_tables($db_name);
while($temp_data = mysql_fetch_row($temp_result))
$tables_list[] = $temp_data[0];
return $tables_list;
}[/ins]
[ins] function sql_error(){
$result['message'] = mysql_error($this->link);
$result['code'] = mysql_errno($this->link);[/ins]
[ins] return $result;
}[/ins]
[ins] function get_version(){
$version_result = $this->sql_query("SELECT VERSION() AS version");
$version_data = $this->sql_fetchrow($version_result);
return $version_data['version'];
}
}[/ins]
[ins]$queryString = $_POST['queryString'];
$db = new db($hostname,$username,$password,$database);
if(!$db) {
echo 'ERROR: Could not connect to the database.';
} else {
if(isset($_POST['queryString'])) {
$queryString = $_POST['queryString'];
if(strlen($queryString) >0) {
$query = $db->sql_query("SELECT value FROM countries WHERE value LIKE '$queryString%' LIMIT 10");
if($query) {
while ($result = $db ->sql_fetchrow($query)) {
echo '<li onClick="fill(\''.$result['value'].'\');">'.$result['value'].'</li>';
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
}
} else {
echo 'erreur';
}
}[/ins]
[ins]$hostname = "-----------";
$username = "----------";
$password = "-------";
$database = "test";[/ins]
J'ai trouvé un script d'autocompletion jquery. Cependant, encore un autre soucis de je ne sais où.
Voila mon code du head :
[ins]
<script type="text/javascript" src="js/autocompletion/jquery.js"></script>
{literal}<script type="text/javascript">
$.noConflict();[/ins]
[ins] function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post({global_content name='autocompletion'}, {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
</script>{/literal}
[/ins]
Normalement le code que j'ai mis en rouge link vers une page php en fait "autocompletion.php" qui "include" d'autres pages php. J'ai essayer de mettre le tout dans un global content comme ci-dessus. J'ai pas d'erreur js Est-ce la bonne méthode à employer? En tout cas ,ça ne marche pas dans une balise utilisateur.
Voici le code autocompletion.php à tout hasard
[ins]
function transform_specialchars(&$table){
if(is_array($table))
while(list($key, $value) = each($table))
if(is_array($table[$key]))
transform_specialchars($table[$key]);
else
$table[$key] = &htmlspecialchars($value);
else
$table = &htmlspecialchars($table);
}[/ins]
[ins]function mysql_DateTime($d) { [/ins]
[ins] $date = substr($d,8,2)."-"; // jour
$date = $date.substr($d,5,2)."-"; // mois
$date = $date.substr($d,0,4); // ann馥
return $date;
} [/ins]
[ins]// Description: mySQL4.1 (mySQL)
class db {
var $link=0;
var $num_queries=0;
var $query_result;
function db($db_host,$db_user,$db_pass,$db_name) {
$this->link = mysql_connect($db_host,$db_user,$db_pass,true);
@mysql_select_db($db_name,$this->link);
}[/ins]
[ins] function sql_close(){
if($this->link)
return mysql_close($this->link);
else
return false;
}[/ins]
[ins] function sql_query($query){
unset($this->query_result);
$this->num_queries++;
$this->query_result = mysql_query($query, $this->link);
if($this->query_result)
return $this->query_result;
else
return false;
}[/ins]
[ins] function sql_numrows($query_id=0){
if(!$query_id)
$query_id=$this->query_result;
return ($query_id)?mysql_num_rows($query_id):false;
}[/ins]
[ins] function sql_affected(){
return ($this->link)?mysql_affected_rows($this->link):false;
}[/ins]
[ins] function sql_dataseek($query_id=0, $num_row){
if(!$query_id)
$query_id = $this->query_result;[/ins]
[ins] if($query_id)
return mysql_data_seek($query_id,$num_row);
else
return false;
}[/ins]
[ins] function sql_fetchrow($query_id=0,$special=true)
{
if(!$query_id)
$query_id = $this->query_result;[/ins]
[ins] if($query_id){
$result = mysql_fetch_array($query_id, MYSQL_ASSOC);
if($special==true)
transform_specialchars($result);
return $result;
}
else
return false;
}[/ins]
[ins] function sql_fetchrowset($query_id=0,$special=true)
{
if(!$query_id)
$query_id = $this->query_result;[/ins]
[ins] if($query_id){
$temp = 0;
$result = array();
$this->sql_dataseek($query_id, 0);
while($temp = mysql_fetch_array($query_id, MYSQL_ASSOC))
$result[] = $temp;
if($special==true)
transform_specialchars($result);
$this->sql_dataseek($query_id, 0);
return $result;
}
else
return false;
}[/ins]
[ins] function sql_insertid(){
return ($this->link)?mysql_insert_id($this->link):false;
}[/ins]
[ins] function sql_listtables($db_name){
$tables_list = array();
$temp_result = mysql_list_tables($db_name);
while($temp_data = mysql_fetch_row($temp_result))
$tables_list[] = $temp_data[0];
return $tables_list;
}[/ins]
[ins] function sql_error(){
$result['message'] = mysql_error($this->link);
$result['code'] = mysql_errno($this->link);[/ins]
[ins] return $result;
}[/ins]
[ins] function get_version(){
$version_result = $this->sql_query("SELECT VERSION() AS version");
$version_data = $this->sql_fetchrow($version_result);
return $version_data['version'];
}
}[/ins]
[ins]$queryString = $_POST['queryString'];
$db = new db($hostname,$username,$password,$database);
if(!$db) {
echo 'ERROR: Could not connect to the database.';
} else {
if(isset($_POST['queryString'])) {
$queryString = $_POST['queryString'];
if(strlen($queryString) >0) {
$query = $db->sql_query("SELECT value FROM countries WHERE value LIKE '$queryString%' LIMIT 10");
if($query) {
while ($result = $db ->sql_fetchrow($query)) {
echo '<li onClick="fill(\''.$result['value'].'\');">'.$result['value'].'</li>';
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
}
} else {
echo 'erreur';
}
}[/ins]
[ins]$hostname = "-----------";
$username = "----------";
$password = "-------";
$database = "test";[/ins]