
04-12-04, 06:27 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Multiple Results
I've got a little out of my depth with this one, so I wonder if anyone can help!
I've go the following code:
The code looks at my message post table and pulls out all of the results ( http://69.73.155.48/index2.php).
All of the above works fine, and I have now created a second table called "comments" and created the input forms for the users. Again, this works fine up till this point.
The problem I am having is that I want to post all of the comments below the relevant posts on the main page. I just cannot get it to work. I've tried nesting another while loop into the code but I keep getting errors. When the user posts a comment it is stored in the comment table with the userID number and the message which it is relevent to.
If anyone can help I would be really greatful!
Last edited by D_tunisia; 04-12-04 at 06:30 PM.
|

04-12-04, 08:57 PM
|
 |
Aspiring Coder
|
|
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Quote:
|
Originally Posted by D_tunisia
I've got a little out of my depth with this one, so I wonder if anyone can help!
I've go the following code:
The code looks at my message post table and pulls out all of the results ( http://69.73.155.48/index2.php).
All of the above works fine, and I have now created a second table called "comments" and created the input forms for the users. Again, this works fine up till this point.
The problem I am having is that I want to post all of the comments below the relevant posts on the main page. I just cannot get it to work. I've tried nesting another while loop into the code but I keep getting errors. When the user posts a comment it is stored in the comment table with the userID number and the message which it is relevent to.
If anyone can help I would be really greatful!
|
I've done something similair. When you pull your "posts" data, get the id.
In your "comments" table, have a field called "post_id", which holds the id of the post that it relates to. Then do a query of the comments table, matching the comments "post_id" to the posts' id, something like SELECT * FROM comments WHERE post_id='$id'". (Something along these lines).
Hope this helps a little.
|

04-12-04, 09:29 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the help, but I really need more advice. I've tried out adding a new while loop within the current one and it isn't working. I would be really greatful if someone can give me some more detail on this one.
The code I have is:
The comments table is called "comments" and the post ID field is "post_id". I'm also not sure how to "get" the post number from the posts table and use it to compare to the comments table.
|

04-12-04, 09:36 PM
|
 |
Coding Addict
|
|
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
try insted of mysql_fetch_row use mysql_fetch_array.. see if that works.
Also can you show me your table structure if this doesn't work.
|

04-13-04, 07:11 AM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm still having a lot of problems with this, does anyone else have any good ideas?
Thanks.
|

04-13-04, 11:21 AM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
use Joins to make it easy!
something like this query might help:
this code will bring each post with its comments ! and will sort them by post time ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|

04-14-04, 12:45 AM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the help. I have entered that code but I keep getting this error:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/ittechni/public_html/index2.php on line 81
Am I doing something silly? Here is the new cde I have:
|

04-14-04, 04:38 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
change this line:
to:
if there is any error, it should be printed to screen, tell us the error message if anything appear ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|

04-14-04, 06:03 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Getting there! I get this error now:
Unknown column 'p.time' in 'order clause'
|

04-15-04, 07:24 AM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
you should've changed it silly !! 
change it to the field name that you want your results to be sorted by or just remove it!
oh, that was long
I assumed that you had a field that contain date/time so just change it as I said !
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Last edited by NeverMind; 04-15-04 at 07:44 AM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|