So, im trying to do a poll, when i run mysql gives me this error, and i dont know what it means.
Warning: max() [function.max]: Array must contain at least one element in …. in line 18.
Could anyone please guide me of whats that?
This is my code:
$query = mysql_query("SELECT * FROM `poll` ORDER BY `id` ASC 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`");
$me = array();
while($row = mysql_fetch_array($query)){
$me[] = $row['hits'];
}
$max = max($me); ////// THIS IS LINE 18
$query = mysql_query("SELECT `questions`.`pid` FROM `responses`, `questions` WHERE `responses`.`qid`=`questions`.`id` AND `responses`.`ip`='".$_SERVER['REMOTE_ADDR']."' AND pid='".$poll['id']."'");
line 18 is noted after “//////”
Any help ? :s
simply what the error-message says:
$meis an empty array (caused by your sql-query returning nothing – why this happens is hard to say without seeing your tablestructure and contents of the table)