Reply to topic
PHP/mysql query problem
jamie
HostMySite Sales Rep
HostMySite Sales Rep

Joined: 19 Mar 2004
Posts: 766
Location: Newark, De
Reply with quote
I'm coding a system for a web-based game that has different elections. I'm storing the election results in a table with four fields

election_id
vote_id
user_id
result

all four fields are integers. Election_id is needed because the table will hold the results for more than one election. Vote_id is an autonumber primary key. User_id is the id number of the user submitting the vote, and 'result' is the id of the person they voted for. I'm now trying to display an html display that shows the top three candidates ordered by the number of votes they each received. I tried something like this

Code:
$current_leaders = dbquery("
 SELECT count(result), result FROM fusion_alliance_votes
 WHERE election_id = '{$election_data['election_id']}'
 Group By Result
 ");


<table>
<tr>
 <td>
 <center><b>Current Standings</b></center>
 </td>
</tr>
<tr>
 <td>
 <center><b>User ID</b></center>
 </td>
 <td>
 <center><b># of Votes</b></center>
 </td>
</tr>

while ($current_leaders_data = dbarray($current_leaders))
{
<tr>
 <td>
 ".$current_leaders_data['result']."
 </td>
 <td>??????????
 </td>
</tr>
}
</table>


But it's not quite right because I can't get the count and ordering right. I thought about subqueries but I don't see how that would help; pretty sure i need some php functions here but I'm not too familiar with php. Any help would be appreciated.
jamie
HostMySite Sales Rep
HostMySite Sales Rep

Joined: 19 Mar 2004
Posts: 766
Location: Newark, De
Reply with quote
This was solved with a subquery - respond here if you want me to post the actual query.
PHP/mysql query problem
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
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic