Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
Bigboy177
Worker
Worker



Joined: Jul 07, 2004
Posts: 192

PostPosted: Fri Jul 09, 2004 4:14 pm Reply with quote

I have An Opros Survey module instead of standard survey module... I want to make Top 10 to work with Opros... But I've got a problem.

In the normal survey in SQL there is a voters... field that shows the total number of Voters... that voted in the survey...

In opros there is no such field... there is only a n_vote field which shows the Votes ID Number... I was wondering if there's a way to read the highest value from this field... No I'm sure it's possible but I don't know how to do it... Could someone please write how to do it... I'm a noob... so write it as simple as possible... Smile
 
View user's profile Send private message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Fri Jul 09, 2004 5:27 pm Reply with quote

Select count(n_vote) as countVotes from some_file
 
View user's profile Send private message
Bigboy177







PostPosted: Fri Jul 09, 2004 6:11 pm Reply with quote

I don't exactly know what you mean...
This is how the table looks like...
Code:


      d_opros n_vote id_q    answer    type_q    
            2   1   2   Super.   radiov   
            2   2   2   Super.   radiov   
            2   3   2   good.    radiov   
            2   4   2   Super.   radiov   
            2   5   2   Super.   radiov   
            2   6   2   Super.   radiov   
            2   7   2   good.    radiov   
            2   8   2   good.    radiov   
            2   9   2   good.    radiov   
            2   10   2   good.    radiov   
            2   11   2   Super.   radiov   
            2   12   2   Super.   radiov   
            2   13   2   Super.   radiov


How can I take out the highest number from the field n_vote...

When I want to take out something from a table... I write something like this:
Code:


$result12 = $db->sql_query("SELECT id, title, hits FROM ".$prefix."_reviews $queryrlang ORDER BY hits DESC LIMIT 0,$top");
if ($db->sql_numrows($result12) > 0) {
    echo "<table border=\"0\" cellpadding=\"10\" width=\"100%\"><tr><td align=\"left\">\n"
   ."<font class=\"option\"><b>$top "._READREVIEWS."</b></font><br><br><font class=\"content\">\n";
    $lugar=1;
    while ($row12 = $db->sql_fetchrow($result12)) {
   $id = intval($row12['id']);
   $title = stripslashes(check_html($row12['title'], "nohtml"));
   $hits = intval($row12['hits']);
   if($hits>0) {


So when I want the script to check the highest value in $hits...
What should I write...

Please help... I'm a total noob... Smile
 
Bigboy177







PostPosted: Sat Jul 10, 2004 7:18 am Reply with quote

Hello.... Smile

Will someone help... please... Razz
 
Raven







PostPosted: Sat Jul 10, 2004 7:24 am Reply with quote

Sorry - have a life - have to sleep sometime Laughing

Please show me what you would expect to see as your output. Then I can show you the SQL.
 
Bigboy177







PostPosted: Sat Jul 10, 2004 7:55 am Reply with quote

As an ouput... I would like to have displayed how many people Voted in my Survey... In the TOP module for the normal Survey the code uses VOTERS field in SQL... bacause there ara all the VOTES
Code:



$result = $db->sql_query("select * from ".$prefix."_poll_desc $queryplang");
if ($db->sql_numrows($result8)>0) {
    echo "<table border=\"0\" cellpadding=\"10\" width=\"100%\"><tr><td align=\"left\">\n"
   ."<font class=\"option\"><b>$top "._VOTEDPOLLS."</b></font><br><br><font class=\"content\">\n";
    $lugar = 1;
    $result2 = sql_query("SELECT pollID, pollTitle, timeStamp, voters FROM ".$prefix."_poll_desc $querylang order by voters DESC limit 0,$top", $dbi);
    $counter = 0;
    while($object = sql_fetch_object($result2, $dbi)) {
   $resultArray[$counter] = array($object->pollID, $object->pollTitle, $object->timeStamp, $object->voters);
   $counter++;
    }
    for ($count = 0; $count < count($resultArray); $count++) {
   $id = $resultArray[$count][0];
   $pollTitle = $resultArray[$count][1];
   $voters = $resultArray[$count][3];
   for($i = 0; $i < 12; $i++) {
       $result3 = sql_query("SELECT optionCount FROM ".$prefix."_poll_data WHERE (pollID='$id') AND (voteID='$i')", $dbi);
       $object = sql_fetch_object($result10, $dbi);
       $optionCount = $object->optionCount;
       $sum = (int)$sum+$optionCount;
   }
   echo "<strong><big>&middot;</big></strong>&nbsp;$lugar: <a href=\"modules.php?name=Surveys&amp;pollID=$id\">$pollTitle</a> - ($sum "._LVOTES.")<br>\n";
   $lugar++;
   $sum = 0;
    }
    echo "</font></td></tr></table><br>\n";
}


I basicaly understand how the above script works...
In my Survey module there's no VOTERS Field... instead there's a N_VOTE field which has VOTES written one by one... I would like to know how to read from the FIELD N_VOTE... What's the HIGHEST NUMBER... in other words HOW MANY PEOPLE VOTED... I don't know how to do that...

I hope you will be able to help... Smile
 
Raven







PostPosted: Sat Jul 10, 2004 8:28 am Reply with quote

What I wanted to see was a 'visual' demonstration of your expected value/output. In other words you showed me the input. Now show me what line or lines you would expect to se in the same form. I'm not asking you for code. In other words are you only trying to extract this line?

2 13 2 Super. radiov
 
Bigboy177







PostPosted: Sat Jul 10, 2004 9:32 am Reply with quote

The Output would be:

Top 10 Surveys:

What's Your Favourite Game?... Votes: 13
How old are you? Votes:25
What's Your Cards Manufacturer? Votes:56


And I want to extract the Number of Votes...
So in a way I would like to extract this line...

2 13 2 Super. radiov

mostly the number 13 because it's the number of the last vote... When the last Voter has the number 26 I would like to extract this number... And so on...

I hope it's clear now... Thanks for all your replies... Smile
 
Raven







PostPosted: Sat Jul 10, 2004 10:37 am Reply with quote

Select max(n_vote) as countVotes from some_file

Now if you'd like to group it by, say type_q, you would do something like this

Select type_q, max(n_vote) as countVotes
from some_file
group by type_q;
 
CodyG
Life Cycles Becoming CPU Cycles



Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island

PostPosted: Fri Jan 05, 2007 10:35 am Reply with quote

Thanks Raven! This was just the info I was looking for this morning.

Code:


SELECT gamename, playername, max( playerscore )
FROM `nuke_flashgames_hiscores_alltime`
GROUP BY gamename
LIMIT 0 , 10

_________________
"We want to see if life is ubiquitous." D.Goldin 
View user's profile Send private message
Raven







PostPosted: Fri Jan 05, 2007 10:56 am Reply with quote

Dance-Y
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©