Jump to content


Photo

seperate poll results


  • Please log in to reply
4 replies to this topic

#1 b_hole

b_hole
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 28 February 2006 - 06:37 PM

I have 3 mysql tables dealing with polls:
poll_questions: id, question, status (status is int, where 0 is future poll, 1 is current poll and 2 is past poll that can't vote for anymore),
poll_answers (for counting non-register voters): id, question_id, answer, hits
members_poll_answers (for counting register voters): question_id, answer_id, member_id.

Each poll has different number of answers.
My problem is to calculate how many registers-users vote for each of the answers in the current poll (status is 1). I want to avoid as many DB connections as I can, but I can't think of a better way than:
-select id from poll_questions where status=1 (lets call the result $qid)
-select id from poll_answers where question_id=$qid (let say X is the number of relevant answers we found)
-X times selecting the count of votes in members_poll_answers table (each time for different answer).

That means a total of X+2 connecting to DB(!).
Can someone help me here to do the same thing just "smarter"?

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 February 2006 - 09:19 PM

How are you storing the responses for the nonregistered voters? Is each response a db entry (meaning lots of db entries), or does each response have a line, and a field on that line (hits) indicated how many times it's been answered (meaning one line for each reponse, with the responses counted in that line)?

#3 markduce

markduce
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 February 2006 - 09:24 PM

Hi,

I think I see what you mean, but post back if I am incorrect.

You could use the mysql_num_rows function to count how many votes you have.


$result=mysql_query("SELECT * FROM poll_answers WHERE question_id='$qid");
$number1=mysql_num_rows($result);
$result2=mysql_query("SELECT * FROM members_poll_answers WHERE question_id='$qid");
$number2=mysql_num_rows($result2);

$total=$number1+$number2;

Is that what you mean?

#4 b_hole

b_hole
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 28 February 2006 - 09:32 PM

[!--quoteo(post=350372:date=Feb 28 2006, 04:19 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Feb 28 2006, 04:19 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
How are you storing the responses for the nonregistered voters? Is each response a db entry (meaning lots of db entries), or does each response have a line, and a field on that line (hits) indicated how many times it's been answered (meaning one line for each reponse, with the responses counted in that line)?
[/quote]
For nonregistered votes I have on one line for each answer, with "hits" to indicate how many times it has been answer.
I don't have a problem showing the nonregistered vote - that easy. My problem is just with registered vote.

[!--quoteo(post=350376:date=Feb 28 2006, 04:24 PM:name=markduce)--][div class=\'quotetop\']QUOTE(markduce @ Feb 28 2006, 04:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]Hi,

I think I see what you mean, but post back if I am incorrect.

You could use the mysql_num_rows function to count how many votes you have.
$result=mysql_query("SELECT * FROM poll_answers WHERE question_id='$qid");
$number1=mysql_num_rows($result);
$result2=mysql_query("SELECT * FROM members_poll_answers WHERE question_id='$qid");
$number2=mysql_num_rows($result2);

$total=$number1+$number2;

Is that what you mean?
[/quote]
You don't understand how my members_poll_answers table works: for each regostered vote I have a different line, that way I can make sure every registered user votes only once for each poll.

#5 b_hole

b_hole
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 02 March 2006 - 11:30 AM

Someone has an idea?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users