This is the page URL
http://domain.com/testphp?id=1&mview=4
The choices are displayed from the table named
je_add_choice and it contains the field names
- choice_id
- poll_id
- choice_creator_id
- choice_name
- choice_image
- description
- Choicecreationtime
It displays the choices with their votes for the particular poll, what i want to do is, I have to display the choices orderby no of votes. But the problem is, The vote count for the choices are from another table named je_user_vote
and it contains the fields
- user_id
- Poll_id
- choice_id
- vote_id (primary key)
- datetime_voted
- usertype
In the poll page i used the query
select * from je_addchoice where poll_id='$poll_id'
In this query the $pollid variable is get from the url $_GET[‘id’]
I want to rewrite the query as
select * from je_addchoice where poll_id='$poll_id' // append the code order by count(fieldname) from je_user_vote table.
I already used
SELECT *, (
SELECT count(*)
FROM je_uservote T2
WHERE T2.pollid=T1.pollID
AND T2.choiceid=T1.choiceID) AS votes
FROM je_addchoice T1
ORDER BY votes
But it shows the blank page. Anybody can help me for solve this problem. Thanks in advance for reading this and help me to solve
All you need is left join and aggregate function to calculate the vote. Here query you can try (untested):