Jump to content

Fetching MYSQL data 2


Ashoar

Recommended Posts

Ok so this was posted originally a few days ago where i received a solution to the problem from Mark.

Although this worked well i am in need of extending this to get more data, but withouth a certain JOIN element in the MYSQL query.

 

What this code here does, is fetches all topics from a certain board. The topics are determined by the parentid='0', which means they are a thread and not a reply.

What i now need to do is also get all replies for each board, which means i need to remove the parentid part of the query.

I thought maybe i could add a second query to do this, but when i do so it just runs through the array and displays the same board over and over as well as the same topic count.

 

Here is the code:

 

$boards = mysql_query("SELECT f.forum_name,
       f.forum_desc,
       f.board,
       COUNT(p.post) AS threads,
       MAX(p.showtime) AS showtime,
       MAX(p.lastposter) AS lastposter
  FROM forums AS f
       LEFT JOIN post_reply AS p ON p.board=f.board AND p.parentid='0'
GROUP BY f.forum_name,
          f.forum_desc,
          f.board
ORDER BY f.forum_id asc")  
or die(mysql_error());

$boards2 = mysql_num_rows($boards);
for($count = 1; $count <= $boards2; $count++)
{
$board = mysql_fetch_array($boards);

 

So is there a way to change this around a bit so that i can get the replies, for each board as well as the posts?

To get the replies it is the same but without parentid, but i cant take parentid out as it will then not show the posts.

Link to comment
https://forums.phpfreaks.com/topic/153726-fetching-mysql-data-2/
Share on other sites

So is there a way to change this around a bit so that i can get the replies, for each board as well as the posts?

To get the replies it is the same but without parentid, but i cant take parentid out as it will then not show the posts.

I have no idea what this means.

 

And that's quite enough bumping.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.