Пример #1
0
function get_post($postid)
{
    validate_post_id($postid);
    $con = db_connect();
    $sql = "SELECT * FROM posts WHERE id={$postid}";
    $result = mysql_query($sql);
    $post = null;
    if (mysql_num_rows($result) > 0) {
        $post = mysql_fetch_array($result);
    }
    db_close($con);
    return $post;
}
Пример #2
0
function write_comments_of_post($postid, $showcomments, $orderby = "posttime", $descending = false)
{
    validate_post_id($postid);
    $top_level = get_top_level_children_of_post($postid, $orderby, $descending);
    if (mysql_num_rows($top_level) > 0) {
        echo "<ol class=\"toplevel\">\n";
        while ($child = mysql_fetch_array($top_level)) {
            write_comment_thread($child['id'], $showcomments, $orderby, $descending);
        }
        echo "</ol>";
        return true;
    } else {
        return false;
    }
}
Пример #3
0
function get_top_level_children_of_post($postid, $orderby = "posttime", $descending = false)
{
    validate_post_id($postid);
    $con = db_connect();
    $orderby = mysql_real_escape_string($orderby);
    $sql = "SELECT * FROM comments WHERE postparent={$postid} AND parent IS NULL ORDER BY {$orderby}";
    if ($descending) {
        $sql = $sql . " DESC";
    }
    $result = mysql_query($sql);
    db_close($con);
    return $result;
}