<?php
class Poll{
function Poll(){
}
function addQuestion( $question , $published ){
$query = "INSERT INTO poll_question ( question , published )
VALUES ( '$question' , '$published' ) ";
print "<br/> $query ";
mysql_query ( $query );
}
function getQuestion(){
$query = "SELECT id , question FROM poll_question
WHERE published = '1' ";
print "<br/> $query ";
$result = mysql_query ( $query );
$data = array();
while ( $row = mysql_fetch_assoc( $result ) ){
$id = $row['id'];
$question = $row['question'];
$data[$id] = $question;
}
return $data;
}
function addAnswer( $answer , $poll_question_id ) {
$query = "INSERT INTO poll_answer ( answer , fk_poll_id )
VALUES ( '$answer' , '$poll_question_id' ) ";
print "<br/> $query ";
mysql_query ( $query );
}
function getAnswer( $poll_question_id ){
$query = "SELECT id , answer FROM poll_answer
WHERE fk_poll_id = '$poll_question_id' ";
print "<br/> $query ";
$result = mysql_query ( $query );
$data = array();
while ( $row = mysql_fetch_assoc( $result ) ) {
$id = $row['id'];
$answer = $row['answer'];
$data[$id] = $answer;
}
return $data;
}
function updateCount ( $id ) {
$query = "UPDATE poll_answer SET score = score + 1
WHERE id = '$id' ";
print "<br/> $query ";
mysql_query ( $query );
}
}
?>
|