MySQL Forums
Forum List  »  PHP

creating a forum website using MySql and PHP. Unsure of how to display topics
Posted by: John Augustine
Date: December 19, 2016 12:01AM

I'm trying to create a website that displays forum threads that have been stored in a database. This is the code I have so far, as far as I'm aware what I've written already is correct but there are some gaps in my code where I'm unsure of how to code this feature. I've commented in the code to explain what I'm trying to do and where I need help.


<?php
//opens connection with database
include 'forum_include.php';
open DB();

//content of each row of forum topics is received
$get_topic_sql = "SELECT * FROM forum_topics";
$get_topic_res = sqlsrv($conn, $get_topic_sql);

//create display_block string, this is the first two rows of the table i'm creating to display the headers
$display_block = <<<END_OF_TEXT
<table style = "border: 1px solid black; border-collapse: collapse;">
<tr>
<th>TOPIC TITLE</th>
<th># of POSTS</th>
</tr>
END_OF_TEXT

//while loop needs to iterate through the results. topic_id, topic_title and topic_owner need to be extracted from the table but i'm unsure of how to do this
while ($topic_info = sql_fetch_array($get_topic_res)) {

$topic_id = ??
$topic_title =
$topic_owner =
}

//number of posts relating to each topic is calculated so it can be added to the "# of posts" column on the website

$get_num_posts_sql = "SELECT COUNT post_id AS post_count FROM forum_posts WHERE topic_id = $topic_id";
$get_num_posts_res = sqlsrv_query($conn, $get_num_posts_sql);

while ($posts_info = $get_num_posts_res) {

//HTML to add each topic in a separate row in the websites table. is this right?
$display_block .= <<<END_OF_TEXT
<tr>
<td><a href = showtopic.php?topic_id=$topic_id>
<strong>$topic_title</strong></a><br/>
created by $topic_owner</td>
<td class = "num_posts_col">$num_posts</td>
</tr>
END_OF_TEXT;

}

free_stmt($get_topic_res);
free_stmt($get_num_posts_res);
sqlsrv_close($conn);

$display_block .= "</table>";
www.grabbitmedia.com
?>

Options: ReplyQuote


Subject
Written By
Posted
creating a forum website using MySql and PHP. Unsure of how to display topics
December 19, 2016 12:01AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.