<commit_before><?php

/*
Functions for getting results from database
*/

//Getting topic count using cat_id
function getTopicCount($cat_id) {
    $query = "SELECT COUNT(*) FROM topics WHERE topic_cat=?";
    $stmt = $GLOBALS["connect"]->prepare($query);
    $stmt->bind_param('i', $cat_id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($topiccount);
    $stmt->fetch();

    return $topiccount;
}

//Getting post count using topic_id
function getPostCount($topic_id) {
    $query = "SELECT COUNT(*)
                FROM posts
                WHERE post_topic=?";
    $stmt = $GLOBALS["connect"]->prepare($query);

    $stmt->bind_param('i', $topic_id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($postcount);
    $stmt->fetch();

    return $postcount;
}

//Getting user post count using user_id
function getUserPosts($user_id) {
    $query = "SELECT COUNT(post_id)
              FROM posts
              WHERE post_by=?";
    $stmt = $GLOBALS['connect']->prepare($query);

    $stmt->bind_param('i', $user_id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($user_post_count);
    $stmt->fetch();

    return $user_post_count;
}
?><commit_msg>Added function to get username from topic_by<commit_after><?php

/*
Functions for getting results from database
*/

//Getting topic count using cat_id
function getTopicCount($cat_id) {
    $query = "SELECT COUNT(*) FROM topics WHERE topic_cat=?";
    $stmt = $GLOBALS["connect"]->prepare($query);
    $stmt->bind_param('i', $cat_id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($topiccount);
    $stmt->fetch();

    return $topiccount;
}

//Getting post count using topic_id
function getPostCount($topic_id) {
    $query = "SELECT COUNT(*)
                FROM posts
                WHERE post_topic=?";
    $stmt = $GLOBALS["connect"]->prepare($query);

    $stmt->bind_param('i', $topic_id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($postcount);
    $stmt->fetch();

    return $postcount;
}

//Getting user post count using user_id
function getUserPosts($user_id) {
    $query = "SELECT COUNT(post_id)
              FROM posts
              WHERE post_by=?";
    $stmt = $GLOBALS['connect']->prepare($query);

    $stmt->bind_param('i', $user_id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($user_post_count);
    $stmt->fetch();

    return $user_post_count;
}

//Getting username from topic_by
function getTopicUsername($topic_id) {
    $query = "SELECT user_name
              FROM users
              WHERE user_id=?";
    $stmt = $GLOBALS['connect']->prepare($query);

    $stmt->bind_param('i', $topic_id);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($username);
    $stmt->fetch();

    return $username;
}
?>
{'fraction_non_alphanumeric': 0.16987067458930444, 'fraction_numerical': 0.0, 'mean_word_length': 3.24, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2201430', 'n_tokens_mistral': 935, 'n_tokens_neox': 905, 'n_words': 189}