1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| <?php
if (!isset($_POST['liste']))
{
?>
<html>
<head>
<title>Liste liée</title>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
//mise en place liste1
$.ajax({
url: "liste_liee.php",
data: "liste=-1",
type: "POST",
success: function(resp){
$('div#liste1').html(resp);
$('div#liste1 select').unbind().bind('change',function(){
$(this).blur();
var id = $(this).val();
$.ajax({
url: "liste_liee.php",
data: "liste="+id,
type: "POST",
success: function(resp){
$('div#liste2').html(resp);
},
error: function(){
alert('error');
}
});
});
},
error: function(){
alert('error');
}
});
});
</script>
</head>
<body>
<div id="liste1" style="float:left;">
</div>
<div id="liste2">
</div>
</body>
</html>
<?php
}
else
{
$link = mysql_connect('localhost','root','mysql') or die(mysql_error());
mysql_select_db('edg',$link) or die(mysql_error());
if ($_POST['liste'] == -1)
{
$sql = "
SELECT id, content
FROM liste1
WHERE id_parent = 0
";
}
else
{
$sql = "
SELECT id, content
FROM liste1
WHERE id_parent = '".$_POST['liste']."'
AND id_parent != 0
";
}
$qry = mysql_query($sql,$link) or die(mysql_error());
?>
<select name="selection<?php echo $_POST['liste']; ?>" size="4" style="width:100px;">
<?php
while ($row = mysql_fetch_assoc($qry))
{
?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['content']; ?></option>
<?php
}
?>
</select>
<?php
}
/*
VOICI LE SQL A AJOUTER DANS LA BASE
IL NE FAUT PAS NON PLUS MODIFIER
- LES PARAMETRES D'ACCES A LA BDD
- LE CHEMIN DE JQUERY src="jquery.js
DROP TABLE IF EXISTS `liste1`;
CREATE TABLE IF NOT EXISTS `liste1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` varchar(32) NOT NULL,
`id_parent` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
--
-- Contenu de la table `liste1`
--
INSERT INTO `liste1` (`id`, `content`, `id_parent`) VALUES
(1, 'A', 0),
(2, 'B', 0),
(3, 'C', 0),
(4, 'A1', 1),
(5, 'B1', 1),
(6, 'A2', 2),
(7, 'A3', 3),
(8, 'B3', 3),
(9, 'C3', 3),
(10, 'D3', 3);
*/
?> |
Partager