My problem in fairly simple. I have a login system constructed using php, mysql databases, and ajax. Everything was working until today when I found a very potential problem that could completely confuse the system. Every single user in the database has a id that is automatically generated by setting auto-increment for the id column to give them a unique id. now my problem is that for example, my chat system, is trying to display all the users in the room. Well, the id for my first user is 1, and the id for the second user is 104. So, php extracts all the users id’s from the database, which is stored in this format:
user1id,user2id,user3id and so on. But when php searches those id’s for id #1 to see if it exists, it finds a 1 in id 104. That’s where the problem starts. Sensing that the user is already in, php changes the record accordingly, and updates the user list to this: 04,1. It was 104,1 before. Now, the script tries to locate the username for id #04, which doesn’t exist. Therefore, a incorrect list of users in the room is given. Now, the most sensible solution to this I think is to add 0’s infront of the shorter id’s, so instead of 104,1,it’s 104,001. But How exactly do I do that with auto increment? Thanks in advance.
My problem in fairly simple. I have a login system constructed using php, mysql
Share
Thanks everyone, but I found a solution. I would get the longest value in the array after explode, and use str_pad to add enough 0’s to the end of every value in the array.