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

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

Post Reply
mikefrederick
Forum Newbie
Posts: 4
Joined: Fri Feb 22, 2008 11:53 am

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

Post 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'"); 
            } 
     }
mikefrederick
Forum Newbie
Posts: 4
Joined: Fri Feb 22, 2008 11:53 am

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

Post by mikefrederick »

Nevermind I got it.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post by Christopher »

You might want to JOIN the three tables, then you could do it with one query.
(#10850)
Post Reply