je viens de créer ce petit script qui permet de faire un tirage au sort :
<!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" />
<title>Noël 2012 Chez Dom</title>
<style>
/*span {
font-size: 36px; background-color:#ffffff;
margin-top: 35px;
margin-left: -490px;
position: absolute;
left: 50%;
width: 980px;
height:500px;
box-shadow: 1px 1px 12px #555;
background: #d3d3d3 url('templates/design_ruffin_tillemont/back.png');
font-family: 'lucida grande',tahoma,verdana,arial,sans-serif;
text-align:center;
}
table {
vertical-align:middle;
}
.conteneur {
margin-left: -490px;
position: absolute;
left: 50%;
display: table-cell;
text-align: center;
vertical-align: middle;
width: 800px;
height: 600px;
background-color:#F00;
}
.conteneur * {
vertical-align: middle;
}
.conteneur span {
display: inline-block;
height: 100%;
}*/
html {
height: 100%;
}
body {
height: 100%;
width:100%;
margin: 0;
padding: 0;
background: #d61d25 url('img/christmas_background.jpg') no-repeat center center;
font-family: 'lucida grande',tahoma,verdana,arial,sans-serif;
font-size:36px;
background-size: 100% 100%;
}
#page-table {
height: 100%;
width: 100%;
border-collapse: collapse;
text-align: center;
}
#page-td {
height: 100%;
padding: 0;
vertical-align: middle;
text-align:center;
}
div#global {
width: 500px;
margin: auto;
text-align: center;
background:#fff;
padding:50px;
box-shadow: 1px 1px 12px #ccc;
margin-top:-170px;
}
</style>
</head>
<body>
<?php
include_once('connection.php');
$mail = $_GET['id_participant'];
$num_participant = $_GET['num_participant'];
$conn = db_connect();
$query = "SELECT * FROM participants WHERE num_participant ='$num_participant' AND id_participant ='$mail'";
$result = mysql_query($query, $conn);
//$parrainage = mysql_fetch_array($result)
$compteur = mysql_fetch_array($result);
// Chercher un nom dans la base
$conn = db_connect();
$sql2 = "select * from participants WHERE num_participant ='$num_participant' AND id_participant ='$mail' AND cadeau_pour is not null";
$resultat2 = mysql_query($sql2, $conn);
$rech_nom = mysql_num_rows($resultat2);
while($rech_nom = mysql_fetch_array($resultat2)) {
if($rech_nom['prenom'] != NULL) {
$name = $rech_nom['prenom'];
}
else {
$name = '0';
}
}
// vérification si utilisateur existe déjà
// $conn = db_connect();
// $sql1 = "select * from participants WHERE num_participant ='$num_participant' AND id_participant ='$mail' AND cadeau_pour != '$name'";
// $resultat1 = mysql_query($sql1, $conn);
// $nbr = mysql_num_rows($resultat1);
if($compteur['validation'] =='0') {
$conn = db_connect();
$sql = "SELECT * FROM participants WHERE id_participant !='$mail' AND cadeau_pour != '$name' ORDER by rand()";
$result = mysql_query($sql, $conn);
while ($row=mysql_fetch_array($result)) {
$cadeau_pour = $row['prenom'];
$validation = $row['validation'];
$num = $row['num_participant'];
$photo = $row['photo'];
}
?>
<table id="page-table">
<tr>
<td id="page-td">
<div id="global">
<?php
//echo "<img src=\"$photo\" style=\"padding-top:10px;\" />";
echo htmlentities($cadeau_pour);
if($result)
$conn = db_connect();
$sql = "UPDATE participants SET validation = '1' cadeau_pour = '$cadeau_pour' WHERE id_participant = '$mail'";
$result = @mysql_query($sql, $conn);
// $sql_cadeaux = "UPDATE cadeaux SET cadeau_pour = '$cadeau_pour' WHERE id_participant = '$mail'";
// $result_cadeaux = @mysql_query($sql_cadeaux, $conn);
?>
<br />
<img src="img/cadeau-noel-ouvert.jpg" style="padding-top:10px;" />
</div><!-- #global -->
</td></tr></table>
<?php
}
else {
$conn = db_connect();
$sql = "SELECT * FROM participants WHERE id_participant ='$mail' AND num_participant ='$num_participant'";
$result = mysql_query($sql, $conn);
$nom_pour_cadeau =mysql_fetch_array($result);
?>
<table id="page-table">
<tr>
<td id="page-td">
<div id="global" style="font-size:17pt;">
Tu dois déjà faire un cadeau à <?php echo htmlentities($nom_pour_cadeau['cadeau_pour']); ?><br />
Mais Le père Noël te remercie de ta générosité!<br />
<img src="img/livraison_pere_noel.jpg" style="padding-top:10px;" />
</div><!-- #global -->
</td></tr></table>
<?php
}
?>
</body>
</html>
Ma base :
--
-- Structure de la table `participants`
--
CREATE TABLE IF NOT EXISTS `participants` (
`num_participant` int(11) NOT NULL,
`id_participant` varchar(250) NOT NULL,
`nom` varchar(250) NOT NULL,
`prenom` varchar(250) NOT NULL,
`cadeau_pour` varchar(250) NOT NULL,
`validation` int(11) NOT NULL,
KEY `num_participant` (`num_participant`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
et j'aimerai savoir si quelqu'un peut me dire comment je peux faire pour que le les noms tirés au sort ne sorte qu'une seule fois...?Je pense que je ne suis pas trop loin de la solution mais la je bloque.
Merci infiniment pour votre aide.