PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Sat Jul 07, 2012 11:08 am
hi guys,
i get this error:
Warning: Wrong parameter count for max() in /home/mekhamata/domains/topline.me/public_html/poll/poll.php on line 17
and my code is:
Code: Select all
<?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);
?>
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Sat Jul 07, 2012 11:22 am
i tryed to add:
below:
Code: Select all
$query = mysql_query("SELECT COUNT(`id`) as hits FROM `responses` GROUP BY `qid`");
like this:
Code: Select all
$query = mysql_query("SELECT COUNT(`id`) as hits FROM `responses` GROUP BY `qid`");
$me = array();
and didnt succeed
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sat Jul 07, 2012 4:29 pm
Shouldn't it be counting qid?
Code: Select all
SELECT COUNT(`qid`) as hits FROM `responses` GROUP BY `qid`");
(#10850)
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Sat Jul 07, 2012 5:28 pm
Nope :S... they are 2 different columns! :S..the query is 100%...the problem with the max(); what to do before or after :\
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sat Jul 07, 2012 7:43 pm
Probably no rows are selected. Do:
Code: Select all
$me = array();
while($row = mysql_fetch_array($query)){
$me[] = $row['hits'];
}
$max = max($me);
(#10850)
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sat Jul 07, 2012 9:39 pm
Why are you grouping the results? Why not just do a COUNT() over everything? One query and it will always return a row.
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Sun Jul 08, 2012 2:32 am
"Christopher" hi,
i tryed to do i got:
Warning: max() [function.max]: Array must contain at least one element in /home/rrrrrrrrrrrrrr/domains/topline.me/public_html/poll/poll.php on line 18
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Sun Jul 08, 2012 2:38 am
"requinix" hi,
thank you man...i tried to do this:
Code: Select all
$query = mysql_query("SELECT COUNT(`id`) as hits FROM `responses`");
while($row = mysql_fetch_array($query)){
$me[] = $row['hits'];
}
$max = max($me);
and i succeed
... thank you!,but are the query is right ?
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Jul 08, 2012 4:06 am
The SQL is right but your code is much more complicated than it needs to be.
Code: Select all
$row = mysql_query("SELECT COUNT(1) FROM `responses`");
$max = current(mysql_fetch_array($row));
I also can't help but notice you don't even use this $max anywhere...
mikosiko
Forum Regular
Posts: 757 Joined: Wed Jan 13, 2010 7:22 pm
Post
by mikosiko » Sun Jul 08, 2012 8:31 am
looking your selects is not even clear which your objectives are, therefore is not possible to tell you which select you must use or if you have to use group by or not... clearly you have the tables POLLS, QUESTIONS and RESPONSES and obviously they are related.... so, what are you trying to get with all those queries?