MySQL Forums
Forum List  »  PHP

Problems creating a forum website using MySql and PHP. Unsure of how to display topics
Posted by: Huy Duong
Date: July 15, 2017 09:06AM

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.

//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;">
<th>TOPIC TITLE</th>
<th># of POSTS</th>

//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
<td><a href = showtopic.php?topic_id=$topic_id>
created by $topic_owner</td>
<td class = "num_posts_col">$num_posts</td>



$display_block .= "</table>";

Options: ReplyQuote

Written By
Problems creating a forum website using MySql and PHP. Unsure of how to display topics
July 15, 2017 09:06AM

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.