Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Answered How do I create unique ID numbers for each entry in a data text file and get the PHP to reference it when needed?

yumedoll

Active Coder
I’ve been using HTML, CSS and JS for a while now but I'm new to PHP. So I apologize if my syntax is a mess or my explaination is a little confusing :')

I'm using some guestbook code created by the lovely Baccyflap to make a BBS system (I’m not sure what they’re called in the west but in Japan, they were common back in the late 90s) and I’ve managed to create the extra fields that could complete the BBS entry creation process. Being pretty new to PHP, the learning curve was steep but I think I’ve gotten the hang of at least the act of creating new parameters and fields.

This is what I have so far and it’s pretty much ready to go, except I’m trying to wrap my head around doing one thing. If you'd like me to comment the full code do let me know, but I feel like most people think just using inspect element will suffice, so I'm gonna leave that decision to whoever asks ;p

I came across this when looking at the original author's guestbook:
Screenshot 2025-03-06 at 2.24.15 AM.webp

They replied to an entry. I’m kind of curious on how to do this, or even how to make it possible for others to do this as well. What made Japanese BBS so fun back then was the social aspect, the ability to reply to posts and chat. So I was hoping anyone could at least help me with portions of what I'm looking to do. I have emailed him about it and he said he just edited the generated html manually (lol) but I want this to be a more interactive frontend available option than just a thing you "walk over the fences and decorations to create via the tacky control panel" thing.

I can suggest an idea I have on how I would do this from a concept standpoint, although I am open if anyone has a better idea since this is the best I could come up with. I choose this method because I think having and individual reply form under every single post feels a bit troublesome, and I want replies to have all the same fields as a regular post (message, image link, title, etc.) just like a real BBS. So instead, it'll just use the form at the very top.

What I have in mind is to create an extra field in the entry form called “Replying to" where you would input a entry’s ID number and it would post your created entry as a reply to the ID’s corresponding entry instead of a normal individual entry, and maybe for convenience, I could add a “Reply” button on the bottom of every entry that would automatically fill in the ID number into the field when clicked.

However, to do this, I would need to do a few things:..

Establish a function where the PHP generates a unique ID number for each post and writes it to the data text file, checking each time as to reference the last ID number to write a new one. I’m happy with each post simply having a simple number like 0, 1, 2, 3, ..., 100, etc. but I don’t know how I’m supposed to go about it. Every tutorial I find online just says “You have to use x” without providing the syntax, and the official PHP documentation isn’t really helping my mushbrain much either.​
​
I would need to create a new hidden parameter that isn’t part of the entry form that would help indicate which entry a “mini-entry” is replying to. I’m thinking this parameter be at the very end of the line. (If you look in my code, you can see that it creates a line containing each parameter for every post created)​
Right now a line looks like this:​
User, Time, Message, Title​
But I think a line in my case should look like this:​
User, Time, Message, Title, ID Number, Reply Target ID Number​
If you check my code you can see I've already added the last two values to the array at the top, but I am yet to implement it into a line because I still don't know how to create an incrementing ID system.​
​
I would need to figure out how to make it so that replies will appear within the div of it’s corresponding entry, just like the image shown above. Also, kinda scared about how I go about this.​
Additionally, I'd need to figure out to make it so that the code can check whether the post it's replying to is already replying to another post to prevent it becoming a blackhole of divs within divs within divs, and instead just append to the parent post of the reply it's replying to, if that makes sense.​
What I have in mind is to make the "Reply Target ID Number" value of posts not replying to any others set to just null, like just the word "null" and make it so that when a post is created to reply to another post, it will check if the post it is replying to has it's "Reply Target" value set to "null" and if true, it will append to the post. If false however, in which the Reply Target's Reply Target has a valid number, it will just append to well... the Reply Target's Reply Target. I hope this makes sense. @~@​
This would in turn, create a nice, long and neatly packaged thread of posts that I can pack into a little <details> tag for anyone to open and close and keep the BBS clean and tidy. :]​
​
I would need to figure out how to get the field to autofill with the ID number when the “Reply” button is clicked. If this isn’t possible with PHP, I might be able to do this with JS but I’ve never used JS with forms before. So far, I’ve only used JS to develop games that take mathematical logic, meaning while something as simple as writing to a field is new ground for me. Go figure.​
​
I hope I don't sound like a lazy idiot asking this so early into my PHP learning journey but if there's one thing I've learnt about amateur web dev, it's that I learn best by jumping straight into creating a proper project with all the trial and error included in the package. I'm grateful if anyone can help me out and thank you in advance :]

EDIT: I've managed to figure it out with some trial and error and a friend! I don't expect anyone to need the code for it since it's very entry level, but please leave a comment here if you'd like me to paste it for your own use!
 
Last edited:
I’ve been using HTML, CSS and JS for a while now but I'm new to PHP. So I apologize if my syntax is a mess or my explaination is a little confusing :')

I'm using some guestbook code created by the lovely Baccyflap to make a BBS system (I’m not sure what they’re called in the west but in Japan, they were common back in the late 90s) and I’ve managed to create the extra fields that could complete the BBS entry creation process. Being pretty new to PHP, the learning curve was steep but I think I’ve gotten the hang of at least the act of creating new parameters and fields.

This is what I have so far and it’s pretty much ready to go, except I’m trying to wrap my head around doing one thing. If you'd like me to comment the full code do let me know, but I feel like most people think just using inspect element will suffice, so I'm gonna leave that decision to whoever asks ;p

I came across this when looking at the original author's guestbook:
View attachment 2953

They replied to an entry. I’m kind of curious on how to do this, or even how to make it possible for others to do this as well. What made Japanese BBS so fun back then was the social aspect, the ability to reply to posts and chat. So I was hoping anyone could at least help me with portions of what I'm looking to do. I have emailed him about it and he said he just edited the generated html manually (lol) but I want this to be a more interactive frontend available option than just a thing you "walk over the fences and decorations to create via the tacky control panel" thing.

I can suggest an idea I have on how I would do this from a concept standpoint, although I am open if anyone has a better idea since this is the best I could come up with. I choose this method because I think having and individual reply form under every single post feels a bit troublesome, and I want replies to have all the same fields as a regular post (message, image link, title, etc.) just like a real BBS. So instead, it'll just use the form at the very top.

What I have in mind is to create an extra field in the entry form called “Replying to" where you would input a entry’s ID number and it would post your created entry as a reply to the ID’s corresponding entry instead of a normal individual entry, and maybe for convenience, I could add a “Reply” button on the bottom of every entry that would automatically fill in the ID number into the field when clicked.

However, to do this, I would need to do a few things:..

Establish a function where the PHP generates a unique ID number for each post and writes it to the data text file, checking each time as to reference the last ID number to write a new one. I’m happy with each post simply having a simple number like 0, 1, 2, 3, ..., 100, etc. but I don’t know how I’m supposed to go about it. Every tutorial I find online just says “You have to use x” without providing the syntax, and the official PHP documentation isn’t really helping my mushbrain much either.​
​
I would need to create a new hidden parameter that isn’t part of the entry form that would help indicate which entry a “mini-entry” is replying to. I’m thinking this parameter be at the very end of the line. (If you look in my code, you can see that it creates a line containing each parameter for every post created)​
Right now a line looks like this:​
User, Time, Message, Title​
But I think a line in my case should look like this:​
User, Time, Message, Title, ID Number, Reply Target ID Number​
If you check my code you can see I've already added the last two values to the array at the top, but I am yet to implement it into a line because I still don't know how to create an incrementing ID system.​
​
I would need to figure out how to make it so that replies will appear within the div of it’s corresponding entry, just like the image shown above. Also, kinda scared about how I go about this.​
Additionally, I'd need to figure out to make it so that the code can check whether the post it's replying to is already replying to another post to prevent it becoming a blackhole of divs within divs within divs, and instead just append to the parent post of the reply it's replying to, if that makes sense.​
What I have in mind is to make the "Reply Target ID Number" value of posts not replying to any others set to just null, like just the word "null" and make it so that when a post is created to reply to another post, it will check if the post it is replying to has it's "Reply Target" value set to "null" and if true, it will append to the post. If false however, in which the Reply Target's Reply Target has a valid number, it will just append to well... the Reply Target's Reply Target. I hope this makes sense. @~@​
This would in turn, create a nice, long and neatly packaged thread of posts that I can pack into a little <details> tag for anyone to open and close and keep the BBS clean and tidy. :]​
​
I would need to figure out how to get the field to autofill with the ID number when the “Reply” button is clicked. If this isn’t possible with PHP, I might be able to do this with JS but I’ve never used JS with forms before. So far, I’ve only used JS to develop games that take mathematical logic, meaning while something as simple as writing to a field is new ground for me. Go figure.​
​
I hope I don't sound like a lazy idiot asking this so early into my PHP learning journey but if there's one thing I've learnt about amateur web dev, it's that I learn best by jumping straight into creating a proper project with all the trial and error included in the package. I'm grateful if anyone can help me out and thank you in advance :]

EDIT: I've managed to figure it out with some trial and error and a friend! I don't expect anyone to need the code for it since it's very entry level, but please leave a comment here if you'd like me to paste it for your own use!
That’s awesome! Trial and error is a great way to learn, but having some basics covered first can help too. Glad you figured it out!
 
Back
Top Bottom