par
patrice.dum » 06 sept. 2009, 10:43
Bonjour, j'ai essaye d'utiliser jquery mais je bloque toujours sur mon pb, en faisant des recherche j'ai bien trouvé un exemple que je n'arrive pas à transcrire dans mon cas (
http://www.codeassembly.com/Simple-chai ... or-jQuery/)
en fait dans mon cas j'ai 5 requête lié à une base de donnée

quelqu'un peut il m'aider car je m'en sort plus help!!! merci
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="js/jquery.chainedSelects.js" type="text/javascript"></script>
<script type="text/javascript">
$(function()
{
$('#Liste1').chainSelect('#Liste2','combobox.php',
{
before:function (target) //before request hide the target combobox and display the loading message
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target) //after request show the target combobox and hide the loading message
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
$('#Liste2').chainSelect('#Liste3','combobox.php',
{
before:function (target)
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target)
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
$('#Liste3').chainSelect('#Liste4','combobox.php',
{
before:function (target)
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target)
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
$('#Liste4').chainSelect('#Liste5','combobox.php',
{
before:function (target)
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target)
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
});
</script>
<style>
#loading {
position:absolute;
top:0px;
right:0px;
background:#ff0000;
color:#fff;
font-size:14px;
font-familly:Arial;
padding:2px;
display:none;
}
</style>
<title>Document sans titre</title>
</head>
<body>
<div id="loading">Loading ...</div>
<div id="Les5LD">
<p>Select your choice from the drop-down lists.</p>
<form name="formname" method="post" action="">
<!-- <form method="post" action="search_sales.html" class="_form" id="search_id">-->
<!-- country combobox -->
<?PHP
include ("includes/config.inc.php");
$rq="Select pays, id FROM matable WHERE quartier = 'n' AND publie = 'o' GROUP BY pays ORDER BY pays ASC";
$rq_pos_id=1;
$rq_pos_val=0;
$result= mysql_query ($rq) or die ("Select impossible");
$retour = '<p><label for="Liste1">Pays :</label>
<select name="Liste1" id="Liste1" size="1">';
$retour .= '<option selected value="">Choisir...</option>';
if (mysql_num_rows($result) != 0) {
while ($row = mysql_fetch_row($result)) {
$retour .= '<option value="'. $row[$rq_pos_val] .'">'. $row[$rq_pos_val] .'</option>';
}
$retour .= '</select></p>';
echo $retour;
}
?>
<p><label for="Liste2">Geographique Zone :</label>
<select name="Liste2" id="Liste2" style="display:none">
</select>
</p>
<p><label for="Liste3">Locality :</label>
<select name="Liste3" id="Liste3" style="display:none">
</select>
</p>
<p><label for="Liste4">Type :</label>
<select name="Liste4" id="Liste4" style="display:none">
</select>
</p>
<p><label for="Liste5">Budget :</label>
<select name="Liste5" id="Liste5" style="display:none">
</select>
</p>
</form>
</div>
</body>
</html>
(les codes aux niveaux des requétes n'est pas bon (<option...) mais je le met pour donnée une idée des valeurs que je souhaite récupérer)
<?php
/* Exemple du code trouvé
$array = array();
if ($_GET['_name'] == 'Liste1')
{
$array = array();
if ($_GET['_name'] == 'country')
{
if ( $_GET['_value'] == 3 )//usa
{
$array[] = array('1' => 'New York');
$array[] = array('2' => 'Montana');
$array[] = array('3' => 'Texas');
} else
{
$array[] = array('0' => 'No state');
}
} elseif ($_GET['_name'] == 'state')
{
if ( $_GET['_value'] == 2 )//New York
{
$array[] = array('1' => 'New York');
$array[] = array('2' => 'Another city');
} else
{
$array[] = array('0' => 'No city');
}
} else
{
$array[] = array('1' => 'Data 1');
$array[] = array('2' => 'Data 2');
$array[] = array('3' => 'Data 3');
$array[] = array('4' => 'Data 4');
$array[] = array('5' => 'Data 5');
}
echo json_encode( $array );
*/
// mon code à moi
//liste 2 ------------------------------------------------------------------------------------------------------
if ( $_GET['_value'] == $Ld1 )
//if (isset($_GET['Ld1'])) {$Ld1_retour = $_GET['Ld1'];}
{
$rq_zone_geographique="Select zone_geographique FROM matable WHERE quartier = 'n' AND publie = 'o' AND pays='".$Ld1_retour."' GROUP BY zone_geographique ORDER BY zone_geographique ASC";
$rq_pos_id_zone_geographique=0;
$rq_pos_val_zone_geographique=0;
$result_zone_geographique= mysql_query ($rq_zone_geographique) or die ("Select impossible");
if (mysql_num_rows($result_zone_geographique) != 0) {
while ($row = mysql_fetch_row($result_zone_geographique)) {
$retour_zone_geographique .= '<option value="'. $row[$rq_pos_val] .'">'. $row[$rq_pos_val] .'</option>';
}
else {
$array[] = array('0' => 'Rien');
}
} else {
$array[] = array('0' => 'Rien');
}
}
//liste 3-----------------------------------------------------------------------------------------------------
if (($Ld1_retour!='')&&($Ld2_retour!='')) {
$rq_locality="Select locality FROM realestate WHERE matable = 'n' AND publie = 'o' AND pays='".$Ld1_retour."' AND zone_geographique='".$Ld2_retour."' GROUP BY locality ORDER by locality ASC;";
// $rq_pos_id=1;
$rq_pos_val_locality=0;
$result= mysql_query ($rq) or die ("Select impossible");
$retour = '<p><label for="Liste3">Locality :</label><select name="Liste3" id="Liste3" size="1" onchange="ValideLd4(this[this.selectedIndex].value);">';
$retour .= '<option selected value="">Choisir...</option>';
if (mysql_num_rows($result) != 0) {
while ($row_locality = mysql_fetch_row($result_locality)) {
$retour_locality .= '<option value="'. $row[$rq_pos_val_locality] .'">'. $row[$rq_pos_val_locality] .'</option>';
}
$retour_locality .= '</select></p>';
} else {
$array[] = array('0' => 'Rien');
}
}
//liste 4-----------------------------------------------------------------------------------------------------
if (($Ld1_retour!='')&&($Ld2_retour!='')&&($Ld3_retour!='')) {
$rq_type_hab="Select type_hab FROM matable WHERE quartier = 'n' AND publie = 'o' AND pays='".$Ld1_retour."' AND zone_geographique='".$Ld2_retour."' AND locality='".$Ld3_retour."' GROUP BY type_hab ORDER BY type_hab ASC;";
//$rq_pos_id=0;
$rq_pos_val_type_hab=0;
$result= mysql_query ($rq) or die ("Select impossible");
if (mysql_num_rows($result) != 0) {
while ($row_type_hab = mysql_fetch_row($result_type_hab)) {
$retour_type_hab .= '<option value="'. $row[$rq_pos_val_type_hab] .'">'. $row[$rq_pos_val_type_hab] .'</option>';
}
} else {
$array[] = array('0' => 'Rien');
}
}
//liste 5-----------------------------------------------------------------------------------------------------
if (($Ld1_retour!='')&&($Ld2_retour!='')&&($Ld3_retour!='')&&($Ld4_retour!='')) {
$rq_id_budget_id="Select matable.id_budget, matable_budget.budget_cat FROM matable, matable_budget WHERE quartier='n' AND publie='o' AND pays='".$Ld1_retour."' AND zone_geographique='".$Ld2_retour."' AND locality='".$Ld3_retour."' AND type_hab='".$Ld4_retour."' AND matable.id_budget = matable_budget.id_budget GROUP BY matable_budget.budget_cat ORDER BY matable_budget.budget_cat ASC";
$rq_pos_id_id_budget=0;
$rq_pos_val_id_budget=1;
$result_id_budget= mysql_query ($rq_id_budget) or die ("Select impossible!");
if (mysql_num_rows($result_id_budget) != 0) {
while ($row_id_budget = mysql_fetch_row($result_id_budget)) {
$retour_id_budget .= '<option value="'. $row[$rq_pos_id_id_budget] .'">'. $row[$rq_pos_val_id_budget] .'</option>';
}
} else {
$array[] = array('0' => 'Rien');
}
}
} else
{
$array[] = array('1' => 'Data 1');
$array[] = array('2' => 'Data 2');
$array[] = array('3' => 'Data 3');
$array[] = array('4' => 'Data 4');
$array[] = array('5' => 'Data 5');
}
mysql_free_result();
mysql_close();
echo json_encode( $array );
?>
Bonjour, j'ai essaye d'utiliser jquery mais je bloque toujours sur mon pb, en faisant des recherche j'ai bien trouvé un exemple que je n'arrive pas à transcrire dans mon cas ([url]http://www.codeassembly.com/Simple-chained-combobox-plugin-for-jQuery/[/url])
en fait dans mon cas j'ai 5 requête lié à une base de donnée :shock: quelqu'un peut il m'aider car je m'en sort plus help!!! merci
[html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="js/jquery.chainedSelects.js" type="text/javascript"></script>
<script type="text/javascript">
$(function()
{
$('#Liste1').chainSelect('#Liste2','combobox.php',
{
before:function (target) //before request hide the target combobox and display the loading message
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target) //after request show the target combobox and hide the loading message
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
$('#Liste2').chainSelect('#Liste3','combobox.php',
{
before:function (target)
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target)
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
$('#Liste3').chainSelect('#Liste4','combobox.php',
{
before:function (target)
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target)
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
$('#Liste4').chainSelect('#Liste5','combobox.php',
{
before:function (target)
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target)
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
});
</script>
<style>
#loading {
position:absolute;
top:0px;
right:0px;
background:#ff0000;
color:#fff;
font-size:14px;
font-familly:Arial;
padding:2px;
display:none;
}
</style>
<title>Document sans titre</title>
</head>
<body>
<div id="loading">Loading ...</div>
<div id="Les5LD">
<p>Select your choice from the drop-down lists.</p>
<form name="formname" method="post" action="">
<!-- <form method="post" action="search_sales.html" class="_form" id="search_id">-->
<!-- country combobox -->
<?PHP
include ("includes/config.inc.php");
$rq="Select pays, id FROM matable WHERE quartier = 'n' AND publie = 'o' GROUP BY pays ORDER BY pays ASC";
$rq_pos_id=1;
$rq_pos_val=0;
$result= mysql_query ($rq) or die ("Select impossible");
$retour = '<p><label for="Liste1">Pays :</label>
<select name="Liste1" id="Liste1" size="1">';
$retour .= '<option selected value="">Choisir...</option>';
if (mysql_num_rows($result) != 0) {
while ($row = mysql_fetch_row($result)) {
$retour .= '<option value="'. $row[$rq_pos_val] .'">'. $row[$rq_pos_val] .'</option>';
}
$retour .= '</select></p>';
echo $retour;
}
?>
<p><label for="Liste2">Geographique Zone :</label>
<select name="Liste2" id="Liste2" style="display:none">
</select>
</p>
<p><label for="Liste3">Locality :</label>
<select name="Liste3" id="Liste3" style="display:none">
</select>
</p>
<p><label for="Liste4">Type :</label>
<select name="Liste4" id="Liste4" style="display:none">
</select>
</p>
<p><label for="Liste5">Budget :</label>
<select name="Liste5" id="Liste5" style="display:none">
</select>
</p>
</form>
</div>
</body>
</html>[/html]
(les codes aux niveaux des requétes n'est pas bon (<option...) mais je le met pour donnée une idée des valeurs que je souhaite récupérer)
[php]<?php
/* Exemple du code trouvé
$array = array();
if ($_GET['_name'] == 'Liste1')
{
$array = array();
if ($_GET['_name'] == 'country')
{
if ( $_GET['_value'] == 3 )//usa
{
$array[] = array('1' => 'New York');
$array[] = array('2' => 'Montana');
$array[] = array('3' => 'Texas');
} else
{
$array[] = array('0' => 'No state');
}
} elseif ($_GET['_name'] == 'state')
{
if ( $_GET['_value'] == 2 )//New York
{
$array[] = array('1' => 'New York');
$array[] = array('2' => 'Another city');
} else
{
$array[] = array('0' => 'No city');
}
} else
{
$array[] = array('1' => 'Data 1');
$array[] = array('2' => 'Data 2');
$array[] = array('3' => 'Data 3');
$array[] = array('4' => 'Data 4');
$array[] = array('5' => 'Data 5');
}
echo json_encode( $array );
*/
// mon code à moi
//liste 2 ------------------------------------------------------------------------------------------------------
if ( $_GET['_value'] == $Ld1 )
//if (isset($_GET['Ld1'])) {$Ld1_retour = $_GET['Ld1'];}
{
$rq_zone_geographique="Select zone_geographique FROM matable WHERE quartier = 'n' AND publie = 'o' AND pays='".$Ld1_retour."' GROUP BY zone_geographique ORDER BY zone_geographique ASC";
$rq_pos_id_zone_geographique=0;
$rq_pos_val_zone_geographique=0;
$result_zone_geographique= mysql_query ($rq_zone_geographique) or die ("Select impossible");
if (mysql_num_rows($result_zone_geographique) != 0) {
while ($row = mysql_fetch_row($result_zone_geographique)) {
$retour_zone_geographique .= '<option value="'. $row[$rq_pos_val] .'">'. $row[$rq_pos_val] .'</option>';
}
else {
$array[] = array('0' => 'Rien');
}
} else {
$array[] = array('0' => 'Rien');
}
}
//liste 3-----------------------------------------------------------------------------------------------------
if (($Ld1_retour!='')&&($Ld2_retour!='')) {
$rq_locality="Select locality FROM realestate WHERE matable = 'n' AND publie = 'o' AND pays='".$Ld1_retour."' AND zone_geographique='".$Ld2_retour."' GROUP BY locality ORDER by locality ASC;";
// $rq_pos_id=1;
$rq_pos_val_locality=0;
$result= mysql_query ($rq) or die ("Select impossible");
$retour = '<p><label for="Liste3">Locality :</label><select name="Liste3" id="Liste3" size="1" onchange="ValideLd4(this[this.selectedIndex].value);">';
$retour .= '<option selected value="">Choisir...</option>';
if (mysql_num_rows($result) != 0) {
while ($row_locality = mysql_fetch_row($result_locality)) {
$retour_locality .= '<option value="'. $row[$rq_pos_val_locality] .'">'. $row[$rq_pos_val_locality] .'</option>';
}
$retour_locality .= '</select></p>';
} else {
$array[] = array('0' => 'Rien');
}
}
//liste 4-----------------------------------------------------------------------------------------------------
if (($Ld1_retour!='')&&($Ld2_retour!='')&&($Ld3_retour!='')) {
$rq_type_hab="Select type_hab FROM matable WHERE quartier = 'n' AND publie = 'o' AND pays='".$Ld1_retour."' AND zone_geographique='".$Ld2_retour."' AND locality='".$Ld3_retour."' GROUP BY type_hab ORDER BY type_hab ASC;";
//$rq_pos_id=0;
$rq_pos_val_type_hab=0;
$result= mysql_query ($rq) or die ("Select impossible");
if (mysql_num_rows($result) != 0) {
while ($row_type_hab = mysql_fetch_row($result_type_hab)) {
$retour_type_hab .= '<option value="'. $row[$rq_pos_val_type_hab] .'">'. $row[$rq_pos_val_type_hab] .'</option>';
}
} else {
$array[] = array('0' => 'Rien');
}
}
//liste 5-----------------------------------------------------------------------------------------------------
if (($Ld1_retour!='')&&($Ld2_retour!='')&&($Ld3_retour!='')&&($Ld4_retour!='')) {
$rq_id_budget_id="Select matable.id_budget, matable_budget.budget_cat FROM matable, matable_budget WHERE quartier='n' AND publie='o' AND pays='".$Ld1_retour."' AND zone_geographique='".$Ld2_retour."' AND locality='".$Ld3_retour."' AND type_hab='".$Ld4_retour."' AND matable.id_budget = matable_budget.id_budget GROUP BY matable_budget.budget_cat ORDER BY matable_budget.budget_cat ASC";
$rq_pos_id_id_budget=0;
$rq_pos_val_id_budget=1;
$result_id_budget= mysql_query ($rq_id_budget) or die ("Select impossible!");
if (mysql_num_rows($result_id_budget) != 0) {
while ($row_id_budget = mysql_fetch_row($result_id_budget)) {
$retour_id_budget .= '<option value="'. $row[$rq_pos_id_id_budget] .'">'. $row[$rq_pos_val_id_budget] .'</option>';
}
} else {
$array[] = array('0' => 'Rien');
}
}
} else
{
$array[] = array('1' => 'Data 1');
$array[] = array('2' => 'Data 2');
$array[] = array('3' => 'Data 3');
$array[] = array('4' => 'Data 4');
$array[] = array('5' => 'Data 5');
}
mysql_free_result();
mysql_close();
echo json_encode( $array );
?>
[/php]