IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Undefined variable


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Inscrit en
    Mai 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 1
    Par défaut Undefined variable
    Bonjour,
    je réalise un site web dynamique et lors de la conception d'un sondage en php, j'ai rencontré un 'tit problème
    mon code est le suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
     
    <?php
     
    $query = mysql_query("SELECT * FROM 'poll' ORDER BY 'id' DESC LIMIT 1");
     
    $rows = mysql_num_rows($query);
     
     
    if($rows > 0){
    $poll = mysql_fetch_array($query);
     
    $title = $poll['name'];
     
    } else {
    $title = 'No Poll Yet';
     
    }
     
    $query = mysql_query("SELECT COUNT('id') as hits FROM 'responses' GROUP BY 'qid'");
     
    while($row = mysql_fetch_array($query)){
    $me[] = $row['hits'];
     
    }
    $max = max($me);
     
     
    $query = mysql_query("SELECT 'questions'.'pid' FROM 'responses', 'questions' WHERE 'responses'.'qid'='questions'.'id' AND 'responses'.'ip'='".$_SERVER['REMOTE_ADDR']."' AND pid='".$poll['id']."'");
     
    if(mysql_num_rows($query) > 0){
    $total = mysql_query("SELECT 'questions'.'pid' FROM 'responses', 'questions' WHERE 'responses'.'qid'='questions'.'id' AND pid='".$poll['id']."'");
    $total = mysql_num_rows($total);
    ?>
    <style type="text/css">
    <!--
    .maintable {
    font-size: x-small;
    font-family: "Times New Roman", Times, serif;
    background-color: #F00;
    }
    .maintable tr .title {
    font-size: 12px;
    }
    .maintable tr td form .question tr td {
    font-size: 12px;
    }
    -->
    </style>
     
    <table width="127" border="0" align="center" cellpadding="0" cellspacing="0" class="maintable">
    <tr>
    <td width="127" align="center" valign="top" class="title"><?php echo $title; ?></td>
    </tr>
    <?php
    $query = mysql_query("SELECT * FROM 'questions' WHERE 'pid'='".$poll['id']."' ORDER BY 'question'");
    $questions = mysql_num_rows($query);
    if($questions > 0){
    ?>
    <tr>
    <td valign="top" style="padding: 5px; font-size: 12px;">
    <table width="100%" cellpadding="0" cellspacing="0" border="0" class="question">
    <?php
    while($question = mysql_fetch_array($query)){
    $responses = mysql_query("SELECT count(id) as total FROM 'responses' WHERE qid='".$question['id']."'");
    $responses = mysql_fetch_array($responses);
     
    if($total > 0 && $responses['total'] > 0){
    $percentage = round(($responses['total'] / $max) * 100);
    } else {
    $percentage = 0;
    }
     
    $percentage2 = 100 - $percentage;
    ?>
    <tr>
    <td valign="top" nowrap="nowrap"><?php echo $question['question']; ?></td>
    <td valign="top" height="10" width="100%" style="padding: 0px 10px; font-size: small; font-family: 'Times New Roman', Times, serif;">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td valign="top" width="<?php echo $percentage; ?>%" <?php if($percentage > 0){?>style="background: url('images/bar.jpg') repeat-x;"<?php } ?>><img src="images/dot.gif" width="1" height="19" /></td>
    <td valign="top" width="<?php echo $percentage2; ?>%"></td>
    </tr>
    </table>
    </td>
    <td valign="top"><?php echo $responses['total']; ?></td>
    </tr>
    <?php
    }
    ?>
    <tr>
    <td valign="top" colspan="3" align="center" style="padding: 10px 0px 0px 0px; font-size: 12px;">Total Votes: <?php echo $total;
    ?></td>
    </tr>
    </table>
    </td>
    </tr>
    <?php
    }
    ?>
    </table>
    <?php
    } else {
    ?>
    <table width="127" cellpadding="0" cellspacing="0" border="0" class="maintable" align="center">
    <tr>
    <td width="127" align="center" valign="top" class="title"><?php echo $title; ?></td>
    </tr>
    <?php
    $query = mysql_query("SELECT * FROM 'questions' WHERE 'pid'='".$poll['id']."' ORDER BY 'question'");
    $questions = mysql_num_rows($query);
    if($questions > 0){
    ?>
    <tr>
    <td valign="top" style="padding: 5px; font-size: 12px;">
    <form name="poll" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <table width="100%" cellpadding="0" cellspacing="0" border="0" class="question">
    <?php
    if(isset($error)){
    ?>
    <tr>
    <td valign="top" colspan="2" align="center" style="padding: 0px 0px 10px 0px;"><?php echo $error; ?></td>
    </tr>
    <?php
    }
    ?>
    <?php
    while($question = mysql_fetch_array($query)){
    ?>
    <tr>
    <td valign="top" style="padding: 0px 10px 0px 0px;"><input type="radio" name="questions" value="<?php echo $question['id']; ?>" /></td>
    <td valign="top" width="100%"><?php echo $question['question']; ?></td>
    </tr>
    <?php
    }
    ?>
    <tr>
    <td valign="top" colspan="2" align="center" style="padding: 10px 0px 0px 0px;"><input type="submit" name="vote" value="Submit Vote" /><br /></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    <?php
    }
    ?>
    </table>
    <span class="maintable"></span>
    <?php
    }
    ?>
    <table width="127" cellpadding="0" cellspacing="0" border="0" align="center">
    <tr>
    <td width="127" align="right" valign="top"> </td>
    </tr>
    </table>
    j'ai bien crée mes tables mysql, tout marche sauf que j'ai ce message:

    Notice: Undefined variable: me in D:\EasyPHP5.3.0\www\poll.php on line 24

    Warning: max() [function.max]: When only one parameter is given, it must be an array in D:\EasyPHP5.3.0\www\poll.php on line 24
    merci de bien vouloir m'aider

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Chez mysql on utilise ` ou rien pour les noms d'objets mais pas '

    Pour avoir le plus grand compte, fait le directement dans ta requête :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $query = mysql_query("SELECT COUNT(*) as hits FROM responses GROUP BY qid ORDER BY hits DESC LIMIT 1");
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre Expert Avatar de Madfrix
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    2 326
    Détails du profil
    Informations personnelles :
    Localisation : France, Gironde (Aquitaine)

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 326
    Par défaut
    rajoute ca avant ton while :

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $me = array();

Discussions similaires

  1. Undefined variable: Idclic
    Par kratos59 dans le forum Langage
    Réponses: 7
    Dernier message: 11/05/2006, 16h50
  2. Notice: Undefined variable
    Par oranoutan dans le forum Langage
    Réponses: 19
    Dernier message: 21/12/2005, 22h28
  3. undefined variable
    Par ept35 dans le forum Langage
    Réponses: 3
    Dernier message: 30/11/2005, 15h48
  4. Notice: Undefined variable
    Par kayn dans le forum Langage
    Réponses: 2
    Dernier message: 03/10/2005, 20h44
  5. Réponses: 3
    Dernier message: 22/09/2005, 11h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo