[RESOLU] Affichage Unique

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RESOLU] Affichage Unique

Re: Affichage Unique

par orell1 » 18 déc. 2012, 11:54

Merci beaucoup!
je vais regarder ça

Merci vraiment.

Re: Affichage Unique

par sirakawa » 18 déc. 2012, 11:52

En gros:
 
//je suppose que tu sais teconnecter à mysql...
   $conn = db_connect();
   $sql2 = "select * from participants WHERE cadeau_pour is null";//modif je suppose qu'on cherche ceux qui n'ont pas déjà eu de cadeau
   $resultat2 = mysql_query($sql2, $conn);
   $rech_nom = mysql_num_rows($resultat2);
   $possibles = array();//ajout
   $indice =0;//ajout
   while($rech_nom = mysql_fetch_array($resultat2)) 
 {
   $indice ++;//ajout   
   $id_participant = $rech_nom['id_participant'];    //ajout
   $possibles[$indice]['id_participant'] = $id_participant; //ajout
   $possibles[$indice]['cadeau'] = 0; //ajout (superflu, mais je pense que ça va aider à comprendre)
   
 }
print" nombre de participants : $indice"; //pour vérifier
print_r($possibles);//pour vérifier
Je vais acheter à bouffer. La suite si tu désires...

Re: Affichage Unique

par orell1 » 18 déc. 2012, 11:02

Ah oui ça me parait bien comme ça, problème... je ne suis pas assez compétent pour faire ça... :-(
mais merci quand même

Re: Affichage Unique

par sirakawa » 18 déc. 2012, 10:16

Bjr,
je dirais:

quand tu lis ta table, tu stockes tous les id dans un tableau
$nb_possibles = 0;
$possibles = array();
$possibles[1]['idf'] = $id_du_premier;
etc;
$attribués =0;
while ($attribués <=$nbr_cadeaux)
tirage au sort de $nombre entre 1 et $nb_possibles;
si ce nombre n(a pas déja un cadeau:
$possibles[$nombre]['cadeau'} = cadeau
$attribués ++;

Re: Affichage Unique

par orell1 » 18 déc. 2012, 00:48

je suis désolé mais je ne comprends vraiment rien là, je dois le mettre ou ça?
comme ça :
        $conn = db_connect();
        $sql = "SELECT * FROM participants WHERE id_participant !='$mail' IN( SELECT distint cadeau_pour FROM cadeaux )";
        $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'];
}

Re: Affichage Unique

par moogli » 18 déc. 2012, 00:40

quand tu a fait un tirage tu le garde comment ?

A partir du moment où tu répond a cette question tu sais dans qu'elle table chercher les id a ne pas prendre et ensuite la requête est simple.

select * from latabledesparticipants where id no in( select distint idparticipant from latablequistocklesparticipations ) ;

@+

Re: Affichage Unique

par orell1 » 18 déc. 2012, 00:11

comment ça?

Re: Affichage Unique

par moogli » 18 déc. 2012, 00:07

salut,


retire de la liste les possible participants ceux sont déjà ciblé d'un cadeaux (donc dans la table participation)


@+

Affichage Unique

par orell1 » 17 déc. 2012, 22:19

Bonsoir à tous,
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.