From 147eadd2c2bb6c8c2c9e238a82296c8a840c4aa8 Mon Sep 17 00:00:00 2001 From: Cflip <36554078+cflip@users.noreply.github.com> Date: Sun, 24 Jan 2021 14:14:05 -0700 Subject: Create function to display threads --- category.php | 28 +++------------------------- includes/functions_inc.php | 30 ++++++++++++++++++++++++++++++ index.php | 10 +++------- 3 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 includes/functions_inc.php diff --git a/category.php b/category.php index b26856a..9fffd10 100644 --- a/category.php +++ b/category.php @@ -2,6 +2,7 @@ include_once 'includes/db_inc.php'; include_once 'header.php'; +include_once 'includes/functions_inc.php'; echo '
'; @@ -32,34 +33,11 @@ $result = mysqli_query($dbc, $sql); if (!$result) { die('Error trying to display threads: ' . mysqli_error($dbc)); -} - -echo ''; - -$sql = "SELECT post_id, post_date, user_id, user_name FROM posts JOIN users ON post_author = user_id WHERE post_thread = ? ORDER BY post_id DESC LIMIT 1"; -$stmt = mysqli_stmt_init($dbc); - -if (!mysqli_stmt_prepare($stmt, $sql)) { - die('Could not create thread due to internal error: ' . mysqli_error($dbc)); -} - -while ($row = mysqli_fetch_assoc($result)) { - mysqli_stmt_bind_param($stmt, "i", $row['thread_id']); - mysqli_stmt_execute($stmt); - - $thread_res = mysqli_stmt_get_result($stmt); - $thread = mysqli_fetch_assoc($thread_res); - - echo ''; } -mysqli_stmt_close($stmt); +echo '
ThreadLatest Post
'; - echo '

' . $row['thread_subject'] . '

'; - echo 'by ' . $row['user_name'] . ' on ' . date('M d, Y', strtotime($row['thread_date'])) . ''; - echo '
by ' . $thread['user_name'] . '
'; - echo '' . date('m/d/Y g:ia', strtotime($thread['post_date'])) . '
'; +display_threads($dbc, $result); mysqli_free_result($result); - echo '
ThreadLatest Post
'; include 'footer.php'; \ No newline at end of file diff --git a/includes/functions_inc.php b/includes/functions_inc.php new file mode 100644 index 0000000..c10b65b --- /dev/null +++ b/includes/functions_inc.php @@ -0,0 +1,30 @@ +'; + echo '

' . $row['thread_subject'] . '

'; + echo 'by ' . $row['user_name'] . ' '; + if ($show_category) { + echo 'in ' . $row['cat_name'] . ' '; + } + echo 'on ' . date('M d, Y', strtotime($row['thread_date'])) . ''; + echo 'by ' . $thread['user_name'] . '
'; + echo '' . date('m/d/Y g:ia', strtotime($thread['post_date'])) . ''; + } + + mysqli_stmt_close($stmt); +} \ No newline at end of file diff --git a/index.php b/index.php index fabec83..3672dbe 100644 --- a/index.php +++ b/index.php @@ -57,24 +57,20 @@ include_once 'header.php'; - + '; } + display_threads($dbc, $result, true); mysqli_free_result($result); ?>
Latest ThreadsCategoriesLatest Post
'; - echo '

' . $row['thread_subject'] . '

'; - echo 'by ' . $row['user_name'] . ' on ' . date('M d, Y', strtotime($row['thread_date'])) . '
Posted in ' . $row['cat_name'] .'
-- cgit v1.2.3