[HELP] Join 3 Table, and output based on category and topic.
Posted: Thu Jul 09, 2009 11:50 am
I tried to make a small forum, using php and mysql. But I have problems with the output. It seem`s the output was mess. This is my query+script and the database:
Please help me.....I tried everything in a whole week...I tried googling but...none on the result...please help...
Thanks...
The right output that I want is like this:DataBase:
tbl>1 posting_forum
id_post
id_category
id_topic
title_posting
post
--------------------------
tbl>2 category_forum
id_category
title_category
-------------------------
tbl>3 topic_forum
id_topic
title_topic
intro
-------------------------------------------------------------------------------
$sql=mysql_query("SELECT * FROM posting_forum
LEFT JOIN topic_forum ON posting_forum.id_topic = topic_forum.id_topic
LEFT JOIN category_forum ON posting_forum.id_category = category_forum.id_category
WHERE topic_forum.id_topic=posting_forum.id_post
ORDER BY id_post");
$x=mysql_fetch_array($sql);
echo "Topic: $x[title_topic]";
echo "<br><br>";
echo "Category: $x[title_category]";
echo "<br><br>";
echo "Title: $x[title_posting]";
All I want is the output is more like this forum(phbb). I wanna shows the category, topic and the new post from the database. But now all I can is show all the category and show all topic and show all the latest and new post, everything showed up on the browser. I was using "coalesce" script in query, but the result in get more confusing, the category and the topic showed up but some category shows the newest post but the other category shows the latest post......>> Category: Music
--------------------
>> Topic: Rock Music
>> New Post: Do you know the chord of Blackholesun?
****************************************************************************
>> Topic: Pop Music
>> New Post: I`ll miss the king of pop...
============================================================================
>> Category: IT
--------------------
>> Topic: Hardware
>> New Post: Do you know how to fix a mother board?
****************************************************************************
>> Topic: Software
>> New Post: What is web 2.0?
============================================================================
Please help me.....I tried everything in a whole week...I tried googling but...none on the result...please help...
Thanks...