Welcome Guest, Not a member yet? Register   Sign In
Help with database query.
#1
Exclamation 

Hey guys,

For some reason today I just can't seem to think.

I am currently working on part of my Forums solution, and I am working on the 'delete comment' function. Now where my problem lies is in the 'discussions' table I store the 'last_comment_id'. When you bring up the front page of the forums ( with all the discussions listed ) it says 'Last comment by {username}'. Now on to my question.

Lets say I have 10 comments for that discussion, and just for example sake the ID's of them comments are 1 through to 10. I want to delete 10, what i need to do is grab the comment ID before 10 ( so 9 ) for this discussion. How would I go about doing this?

As I said I know its a really daft question but my brain has turned into mush and I just can't seem to think straight.

Any help would be appreciated guys.

Chris
Reply
#2

(This post was last modified: 04-23-2015, 05:04 AM by Rufnex.)

You can do something like that (with mysql).

PHP Code:
delete from comments where id 10
select id from comments where discussions_id 
= [discussion_idorder by id DESC limit 1
update discussions set last_comment_id 
= [the return value of the select above

Reply
#3

(04-23-2015, 05:03 AM)Rufnex Wrote: You can do something like that (with mysql).

PHP Code:
delete from comments where id 10
select id from comments where discussions_id 
= [discussion_idorder by id DESC limit 1
update discussions set last_comment_id 
= [the return value of the select above

Haha i knew I was over thinking this!

It was the query that I could not think of. Thats great mate thank you very much for the swift reply =)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB