Javascript code to get topic id from post id

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
gvp9000
Registered User
Posts: 60
Joined: Mon Oct 02, 2023 4:03 pm

Javascript code to get topic id from post id

Post by gvp9000 »

Javascript code to get topic id# from post id#.
Is it possible ?

For example if I know the post id = 1234 the function must return the topic id = 21.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53523
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Javascript code to get topic id from post id

Post by Brf »

You wouldn't be able to do that in javascript. Javascript runs in the user's webbrowser, which does not have access to the database. You would have to run some PHP code on the server side to read the database. If you gave us some context, we could offer a better solution.
User avatar
warmweer
Jr. Extension Validator
Posts: 11656
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: Javascript code to get topic id from post id

Post by warmweer »

I'm not sure about this but IIRC cloning a topic does not create new post_ids, only a new topic_id.

If I'm correct, then in that case a post_id would not point to a unique topic_id.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
gvp9000
Registered User
Posts: 60
Joined: Mon Oct 02, 2023 4:03 pm

Re: Javascript code to get topic id from post id

Post by gvp9000 »

Thank you
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53523
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Javascript code to get topic id from post id

Post by Brf »

warmweer wrote: Sun Apr 21, 2024 7:37 am I'm not sure about this but IIRC cloning a topic does not create new post_ids, only a new topic_id.

If I'm correct, then in that case a post_id would not point to a unique topic_id.
That is not true. The posts table post_id is a unique primary key, and is also an auto-increment field. If you clone a topic, the copied posts would automatically get new ids.
User avatar
warmweer
Jr. Extension Validator
Posts: 11656
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: Javascript code to get topic id from post id

Post by warmweer »

Brf wrote: Mon Apr 22, 2024 12:26 pm
warmweer wrote: Sun Apr 21, 2024 7:37 am I'm not sure about this but IIRC cloning a topic does not create new post_ids, only a new topic_id.

If I'm correct, then in that case a post_id would not point to a unique topic_id.
That is not true. The posts table post_id is a unique primary key, and is also an auto-increment field. If you clone a topic, the copied posts would automatically get new ids.
You're right: :thumbsup: I just tested it now but should immediately have realised that I was wrong as in the past (before I discovered) javiexin's copy post extension) I had to clone a topic to create a cloned post.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.

Return to “phpBB Custom Coding”