Jump to content

need help with my comments system


adambedford

Recommended Posts

I've written some simple code that shows a list of music files that are in a database. I'm now trying to add a comments system so that users can add a comment to a specific track.

 

I've got two tables, 'tracks' and 'comments' and the 'comments' table has a field called c_TrackID which relates to the field 't_ID' in the tracks table - all standard stuff.

 

The problem I have is displaying the comments. My first thought was to use a LEFT JOIN query to return a recordset of the two but that hasn't worked out quite as I'd hoped. The query itself is fine but it doesn't repeat the comments within each track, it repeats each combination of track & comment.

 

I'm looking for a solution to repeat all the tracks and within that list repeat all the comments for that particular track.

 

I thought about querying the comments table within the while loop for the tracks but that will be quite slow and cumbersome and I'm sure there is a more efficient and easier way.

 

I'd really appreciate any suggestions!

Link to comment
Share on other sites

Yeah I do, but at the moment it is displaying each track and a single comment and then repeating each track with a different comment. I want the comments to be displayed underneath each track and grouped together so that the tracks only display once.

 

So yeah just to display the comments for each track.

Link to comment
Share on other sites

The querys would have to be something like:

 

<?php
$tracks = mysql_query("SELECT * FROM tracks");
while($tracks_result=mysql_fetch_array($tracks)) {
$comments = mysql_query("SELECT * FROM comments WHERE c_TrackID={$tracks_result['t_ID']}");
while($comment_result=mysql_fetch_array($comments)) {
?>
/*

HTML HERE

/*
<?php
}}
?>

 

If that is what you are doing just make sure there is no LIMIT, if you still have a problem after that. Show us the HTML you are echoing the comments into.

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.