Hi,
I'm working with a site where I will eventually have users in a MySQL database. I'm trying to come up with a well thought out way to management the information so programming will be easier later. I was wondering if anyone suggests another way or has a reason why the scenario I've come up with wouldn't work well. This is what I'm envisioning:
A javascript routine that sets up an object like so:
PHP Code:
function user(firstname,lastname,birthdate) { this.firstname=firstname; this.lastname=lastname; this.birthdate=birthdate; }
A javascript function called populateUserInfo(id) would execute "user.[id] = new user;" and then do an AJAX call (using XMLHttpRequest) that loads a php file with ?userid=[id] appended to it. This file would return the data from all of the fields of the user id. Then it would populate the information like so:
PHP Code:
user.[id].firstname = (the line from responseText that reps the first name) user.[id].lastname = (the line from responseText that reps the last name) user.[id].birthdate = (the line from responseText that reps the birthdate)
and so on. After this is set up then all I would need to do to load a users information into a javascript object would be, for example "populateUserInfo(13)" for user #13. Then for example, I could retrieve user #13's birthdate with user.13.birthdate.
Is this a valid approach? And in either case whether it is valid or not, does anyone have a better suggestion or does this look like an okay way to do things? I'm still learning Javascript (at a fast rate I'm picking it up) and understand most of the concepts, I just haven't done enough projects to really see how many ways certain things can be done so I may be totally missing an obvious easier way and making this harder than it has to be (but hey that's a part of learning!)
Anyone have any suggestions or comments?
|