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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.