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
| <?php
// Mettre ce bout de code dans un petit fichier à inclure sur tes pages (centraliser les fonctions importantes/utiles)
/// config de la base de donnee
define('SQL_SERVER','localhost');
define('SQL_BDD','narcisse');
define('SQL_USER','root');
define('SQL_PASS','');
function connexion() {
$db_link = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASS);
mysql_select_db(SQL_BDD);
}
function close() {
mysql_close();
}
?>
<!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=iso-8859-1" />
<title>diap2</title>
<script type="text/javascript">
var i=0;
function affiche(){
var random = Math.round((Math.random()*(Pic.length-1)));
// Generation d'une valeur alétoire
var nom = Pic[random];
var img=document.createElement('img');
img.src='VersionLocale/'+nom;
document.body.appendChild(img);
setTimeout(function(){affiche();}, 3000);
}
</script>
</head>
<body>
<?php
if(isset ($_POST['Diaporama'])){
$diap = $_POST['Diaporama'];
echo $diap;
connexion();
$id_photo = mysql_query("SELECT id_photo FROM `contient` WHERE `nom_diapo` = '$diap' ");
echo "<script>var Pic = new Array(";
$i=0;
while($donnees = mysql_fetch_array($id_photo)){
$id = $donnees['id_photo'];
$cliche = mysql_query("SELECT cliche FROM `photo` WHERE `id_photo` = '$id' ");
while($donnees2 = mysql_fetch_assoc($cliche)){
$photo = $donnees2['cliche']; // quand tu sors de ta boucle, $photo ne vaut qu'une valeur, la dernière ????!!!
}
if($i>0){echo ",";}
echo "'".$photo."'";
$i++;
}
echo ");</script>";
}else{
echo "Aucun diapo sélectioné";
}
?>
<a onclick="affiche();" style="cursor:pointer;">TRY ME</a> (don't forget to check <img src="http://www.developpez.net/forums/images/buttons/resolu.gif"> on Developpez' forum community and perhaps to write a special thanks to d-Rek) <img src="http://www.developpez.net/forums/images/smilies/icon_biggrin.gif">
</body>
</html> |