Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Managing a user database, looking for suggestions/advice
Old 06-13-2010, 03:36 AM Managing a user database, looking for suggestions/advice
Experienced Talker

Posts: 37
Trades: 0
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?
catatung is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-16-2010, 08:21 AM Re: Managing a user database, looking for suggestions/advice
Extreme Talker

Posts: 246
Trades: 0
Why do you have a flat file with the information when you have a database?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 06-16-2010, 08:50 AM Re: Managing a user database, looking for suggestions/advice
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
So why do you want to make it more complicated by using javascript for what is an extremely simple task in server side code which you will have to write anyway?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Managing a user database, looking for suggestions/advice
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.84497 seconds with 12 queries