HTML and CSS Reference
In-Depth Information
/*
* Because creating a question counts as its first vote, this adds a
* vote for the question to the database
*/
$sql = "INSERT INTO question_votes
VALUES (:question_id, 1)";
$stmt = self::$db->prepare($sql);
$stmt->bindParam(":question_id", $question_id, PDO::PARAM_INT);
$stmt->execute();
$stmt->closeCursor();
return array(
'room_id' => $room_id,
'question_id' => $question_id,
);
}
Adding Votes to a Question
Updating the vote count keeps it simple: the vote_question() method increments the vote count by 1 for the given
question ID. Add this method (in bold) to the Question_Model class:
return array(
'room_id' => $room_id,
'question_id' => $question_id,
);
}
/**
* Increases the vote count of a given question
*
* @param $room_id int The ID of the room
* @param $question_id int The ID of the question
* @return array The IDs of the room and the question
*/
public function vote_question( $room_id, $question_id )
{
// Increments the vote count for the question
$sql = "UPDATE question_votes
SET vote_count = vote_count+1
WHERE question_id = :question_id";
$stmt = self::$db->prepare($sql);
$stmt->bindParam(':question_id', $question_id, PDO::PARAM_INT);
$stmt->execute();
$stmt->closeCursor();
 
Search WWH ::




Custom Search