discussion board with mysql - query problem
Posted: Sun Jan 16, 2005 5:49 pm
I'm building a discussion forum but is having trouble retrieving data.
table structure is:
ALL new topics have a parent = 0. If a parent > 0 thrn it is a reply.
to retrieve the main topics, i use this function:
What i want is a function or code that can retrieve the main topics with it's replies, as in:
How do i combine the two functions to retrieve the main topics and replies together?
thanks
feyd | please use formatting!
table structure is:
Code: Select all
uid auto inc key
parent int
name
title
date
message
timeto retrieve the main topics, i use this function:
Code: Select all
function gettopics(){
include("config.php");
$query="select * from test where parent='0' order by date desc ";
echo '<ul type="disc">';
if ($r =mysql_query($query)){
while ($row =mysql_fetch_array($r)){
$name=$rowї'name'];
$uid=$rowї'uid'];
$title=$rowї'title'];
$message=$rowї'message'];
$date=$rowї'date'];
echo "<li>";
echo "<a href="viewarticle.php?parent=$uid"> $title </a>";
echo "-- by ($name) $date<br/>";
echo "</ul>";
}
}
}
To retrieve the replies:
$parent=$_GETї'parent'];
include("config.php");
$query="select uid,name,title,message,parent,date from test where parent=$parent order by date,parent desc ";
//$query="SELECT * FROM test as t, WHERE t.uid = t.parent ";
//echo '<ul type="disc">';
if ($r =mysql_query($query)){
$num=(mysql_num_rows($r));
//Retrieve records
while ($row =mysql_fetch_array($r)){
$name=$rowї'name'];
$uid=$rowї'uid'];
$title=$rowї'title'];
$message=$rowї'message'];
$date=$rowї'date'];
//add bullet points
echo '<ul type="disc">';
echo "<li>";
echo "<a href="viewarticle.php?parent=$uid"> $title </a>";
echo "-- by ($name) $date<br/>";
echo "</li></ul>";
}
}
else{
print "No replies to this thread";
}
?>What i want is a function or code that can retrieve the main topics with it's replies, as in:
Code: Select all
topic1
reply(to topic1)
reply(to topic1)
topic2
reply(to topic2)
reply(to topic2)thanks
feyd | please use formatting!