Je voudrais recuperer les valeurs (2 a 4 mots) qui se trouvent dans la liste d'un menu deroulant avec PHP+Ajax, mon code est le suivant:
code js:
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","Sawtiyat/Quoran/test.php?id="+str,true);
xmlhttp.send();
}
function showUser2(str)
{
if (str=="")
{
document.getElementById("txtHint2").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint2").innerHTML=xmlhttp.responseText;
}
}
str=encodeURI(str);
xmlhttp.open("GET","Sawtiyat/Quoran/testbis.php?sheikh_ar="+str,true);
xmlhttp.send();
}
index.php:
<form>
<select name="users" onchange="showUser(this.value)">
<option value="0" disabled="disabled" selected="selected">- Select Make</option>
<option value="1">مقرئ</option>
<option value="2">رواية</option>
<option value="3">البلد</option>
</select>
</form>
<div id="txtHint"><b>Person info will be listed here.</b></div>
<div id="txtHint2"><b>Person info will be listed here.</b></div>
test.php:
<font color="purple">this file is test</font>
<br />
<?php
print_r($_GET);
$id = $_GET['id'];
echo 'id'.$id.'<br>';
if ($id == '1')
{
$theorder = 'sheikh_ar';
}
if ($id == '2')
{
$theorder = 'riwaya';
}
if ($id == '3')
{
$theorder = 'nationality';
}
include '../../Included_Files/Connect.php';
// selection DB sawtiyat
mysql_select_db($db_sawtiyat) or die ('Erreur de selection de la BD sawtiyat: '.mysql_error());
// selectionner tous les shiekhs
$select_qr = 'SELECT DISTINCT '.$theorder.' FROM sheikh_tbl WHERE quoran=1';
echo '<font color="red">'.$select_qr.'</font><br>';
$query_qr = mysql_query($select_qr) OR DIE (mysql_error());
$nb = mysql_num_rows($query_qr);
echo 'total: <font color="green">'.$nb.'</font><br>';
echo ' <select name="users2" onchange="showUser2(this.value)">
<option value="0" disabled="disabled" selected="selected">- Select Make</option>';
while ($row_qr = mysql_fetch_array($query_qr))
{
// on extract les donnees
extract($row_qr);
echo 'id'.$id.'<br>';
if ($id == '1')
{
$showme = $sheikh_ar;
}
if ($id == '2')
{
$showme = $riwaya;
}
if ($id == '3')
{
$showme = $nationality;
}
echo '<option value='.$sheikh_ar.'>'.$showme.'</option>';
}
echo '</select>';
echo '</form>';
?>
testbis.php:
<font color="gray">this file is testbis</font>
<br />
<?php
print_r($_GET); // ce print_r affiche juste le premier mot de l'ensemble des mots
$sheikh_ar = $_GET['sheikh_ar'];
echo 'testbis sheikh'.$sheikh_ar.'<br>';
include '../../Included_Files/Connect.php';
// selection DB sawtiyat
mysql_select_db($db_sawtiyat) or die ('Erreur de selection de la BD sawtiyat: '.mysql_error());
$select_qr2 = 'SELECT * FROM sheikh_tbl WHERE quoran=1 AND sheikh_ar = "'.$sheikh_ar.'"';
echo '<font color="red">'.$select_qr2.'</font><br>';
$query_qr2 = mysql_query($select_qr2) OR DIE (mysql_error());
$nb2 = mysql_num_rows($query_qr2);
echo 'total: <font color="green">'.$nb2.'</font><br>';
while ($row_qr2 = mysql_fetch_array($query_qr2))
{
// on extract les donnees
extract($row_qr2);
echo $sheikh_en.' '.$sheikh_ar;
echo $riwaya.' ';
echo $nationality.' ';
echo '<br>';
}
?>
le probleme c'est quand je fais ma 2eme selection, il me donne comme resultat de la variable $sheikh_ar dans testbis.php que le premier mot, ca veut dire, si j'ai comme resultat dans la liste (lolo lola) il affiche juste (lolo).Merci d'avance