Пример #1
0
use utils\mysql;
use utils\response;
use models\question;
use models\answer;
$conn = mysql\connect();
// Get Question's Details
$sql = "\n        SELECT \n            id, name, email, topic, content, votes, create_time\n        FROM \n            questions\n        WHERE\n            id = {$question_id}";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $question = new question\QuestionModel($row);
    }
}
if ($question == null) {
    exit;
}
// Get Answers' Details
$sql = "\n        SELECT \n            id, question_id, name, content, votes, create_time\n        FROM \n            answers\n        WHERE\n            question_id = {$question_id}\n        ORDER BY votes DESC, create_time ASC";
$result = $conn->query($sql);
$answers = array();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $answer = new answer\AnswerModel($row);
        array_push($answers, $answer);
    }
}
$params = array("question" => $question, "answers" => $answers);
mysql\close($conn);
response\render("answer/index.php", $params);
?>
a<?php 
Пример #2
0
<?php

namespace router;

define("ROOT", $_SERVER['DOCUMENT_ROOT']);
require_once ROOT . '/models/question/question.php';
require_once ROOT . '/utils/mysql/connection.php';
require_once ROOT . '/utils/response/render.php';
use utils\mysql;
use utils\response;
use models\question;
$conn = mysql\connect();
$sql = "\n        SELECT \n            Q.id, Q.email, Q.name, Q.topic, Q.content, Q.votes, Q.create_time, A.answers \n        FROM \n            questions Q \n                LEFT JOIN \n            (SELECT \n                question_id, count(distinct id) as answers\n             FROM \n                answers \n             GROUP BY question_id) A\n                on Q.id = A.question_id \n        ORDER BY Q.create_time ASC";
$result = $conn->query($sql);
$questions = array();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $question = new question\QuestionModel($row);
        array_push($questions, $question);
    }
}
mysql\close($conn);
response\render("index.php", array("questions" => $questions));
Пример #3
0
<?php

namespace router\question;

if (!isset($_GET["id"])) {
    exit;
}
$question_id = $_GET["id"];
define("ROOT", $_SERVER['DOCUMENT_ROOT']);
require_once ROOT . '/models/question/question.php';
require_once ROOT . '/utils/mysql/connection.php';
require_once ROOT . '/utils/response/render.php';
use utils\mysql;
use utils\response;
use models\question;
$conn = mysql\connect();
// Get Question's Details
$sql = "\n        SELECT \n            id, name, email, topic, content\n        FROM \n            questions\n        WHERE\n            id = {$question_id}";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $question = new question\QuestionModel($row);
    }
}
if ($question == null) {
    exit;
}
$params = array("question" => $question);
mysql\close($conn);
response\render("ask/index.php", $params);
Пример #4
0
<?php

namespace router\ask;

define("ROOT", $_SERVER['DOCUMENT_ROOT']);
require_once ROOT . '/utils/response/render.php';
use utils\response;
response\render("ask/index.php");