My tables look like this:
qotwQuestion1a QuestionId [primarykey] Question MemberId PostDate qotwVote1a QuestionId [primarykey] MemberId [primarykey] Vote1a qotwMember MemberId [primarykey] Name Password emailId
The Sql query below sums the number of votes for each questionId (which has a postDate between the startofweek and endofweek date) and then displays it.
$result2 = mysql_query(" SELECT * FROM qotwMember, qotwQuestion1a
WHERE qotwMember.MemberId=qotwQuestion1a.MemberId
AND PostDate>='".$startofweek."' AND PostDate<='".$endofweek."'
ORDER BY qotwQuestion1a.QuestionId DESC ");
while($row2 = mysql_fetch_array($result2))
{ //echo("testing");
$result3= mysql_query ("SELECT SUM(Vote1a) AS total FROM qotwVote1a
WHERE QuestionId='".$row2['QuestionId']."'
ORDER BY total DESC ");
while($row3 = mysql_fetch_array($result3))
{
echo $row2['Question'] . " " .$row2['Name'] . " " .$row3['total'];
}
}
This query works fine, except for the "ORDER BY total DESC". The query gives the result, but does not orders the result by "total". But my issue is to get the questionId which has the maximum number of votes. if there is a tie between a few questionIds, i would need all of those questions.
Can someone help me with this
Best Zeeshan