Problème script php, heeeelp plzzz

Résolu/Fermé
minoucha1987 - 31 mai 2010 à 23:29
 minoucha1987 - 1 juin 2010 à 16:04
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 :
<?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 :)
A voir également:

1 réponse

Bonsoir,

Vous n'initialisez pas l'array $me avant de l'utiliser.

Ajoutez $me = array(); avant votre boucle.
1
minoucha1987
1 juin 2010 à 16:04
merci pour ton aide, j'ai ajouté $me = array(); avant la boucle mais j'ai un message:
Warning: max() [function.max]: Array must contain at least one element in D:\EasyPHP5.3.0\www\poll.php on line 24
:( je ne c pas quoi faire
0