Page 1 of 1

HELPPP with this array please, and thanks ahead of time!

Posted: Fri Feb 22, 2008 12:09 pm
by mikefrederick
Thanks for any help....For each field id from table regions, I need to go through each candidate field 'name' from table 'candidates', and record the number of times that the 'answerid' from table newvotes (equal to the 'id' field from table 'candidates') occurs for the region. At the end of going through each region, I need to record which answerid showed up the most times. At the end, I need to record the total number of times each answerid or candidateid showed up the most for a region (this shows the total number of regions that the candidate won) and be able to echo it in a <td> . I almost had it working, but the way I was doing it was not efficient and so I am starting over and asking for help. Thanks ahead of time (the code below at least helps with the setup of the while loops and the tables)!

Code: Select all

 
    $d=mysql_query("select * from regions order by id");
     while($s=mysql_fetch_assoc($d)) {
            $l=mysql_query("select * from candidates order by name");
            while($i=mysql_fetch_assoc($l)) {
                 $regionid=$s['id'];
                 $answerid=$i['id'];
                 $u=mysql_query("select * from newvotes where answerid='$answerid' and regionid='$regionid'"); 
            } 
     }

Re: HELPPP with this array please, and thanks ahead of time!

Posted: Fri Feb 22, 2008 12:15 pm
by mikefrederick
Nevermind I got it.

Re: HELPPP with this array please, and thanks ahead of time!

Posted: Fri Feb 22, 2008 12:16 pm
by Christopher
You might want to JOIN the three tables, then you could do it with one query.