SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DB and coding logic of a simple addressbook app.

    Hello,

    I would like to make an adress book app. I got the skills to achieve this goal in PHP. However I have a problem.

    I have no idea about how to let user add multiple phone numbers, addresses, emails etc just like in today's mobile phones. How can I do this? I mean, how shall I design the DB in order to achieve this? Arrays? Or another table to store these datas and get the record count when showing phone number boxes etc?

    What would you suggest?

    Thank you very much for your ideas, highly appriciated.

  2. #2
    SitePoint Addict
    Join Date
    Nov 2008
    Location
    Peterborough, Ontario, Canada
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The easiest way would be to do it the same way every cell phone does it (and most email client's address books). Just add extra fields... Like:

    Home Phone:
    Cell Phone:
    Work Phone:

    Personal Email:
    Business Email:

    Ect...
    Have I helped you? You could help me.
    Like my business on facebook!
    Text message polls with real-time, live results.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2008
    Location
    Peterborough, Ontario, Canada
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or (as I'm not sure what you're asking)

    If you mean, how do I let a user store more than one contact, then you just add a field to your database that says who the contact belongs to.

    For example:

    You could add the field "owner" and put the user's id number or name who created it.
    Have I helped you? You could help me.
    Like my business on facebook!
    Text message polls with real-time, live results.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    users
    -- id

    phone_numbers
    -- id
    -- user_id

    addresses
    -- id
    -- user_id

    emails
    -- id
    -- user_id

    Seems like your pretty generic one to many scenario unless I'm missing something.

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    First of all thank you for your reply. However this is not what I am looking for eventhough this is the simplest solution. Well, Just like in cellphones, I want to let the user decide how many of which he/she wants. Maybe 2 cell phones, or 3. So fixed DB table won't work. Maybe arrays but I don't know.

    What do you think?

    Quote Originally Posted by jeffvdovjak View Post
    The easiest way would be to do it the same way every cell phone does it (and most email client's address books). Just add extra fields... Like:

    Home Phone:
    Cell Phone:
    Work Phone:

    Personal Email:
    Business Email:

    Ect...

  6. #6
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Thank you for you reply as well. This is a nice one, but What do I do when a user wants to edit a contact? Dynamically generate input fields? And yeah, I can generate input fields dynamically but how am I supposed to retrieve data from them and perform a mysql record update at the same time deleting some records if user removes phone numbers during editing process for example.. :s

    Thank you!

    Quote Originally Posted by oddz View Post
    users
    -- id

    phone_numbers
    -- id
    -- user_id

    addresses
    -- id
    -- user_id

    emails
    -- id
    -- user_id

    Seems like your pretty generic one to many scenario unless I'm missing something.

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    Everything your talking about is domain based logic. The structure seems like it fits your needs though. Moving the information between the domain and db is another problem that requires more specifics.

  8. #8
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean domain based logic?

    Quote Originally Posted by oddz View Post
    Everything your talking about is domain based logic. The structure seems like it fits your needs though. Moving the information between the domain and db is another problem that requires more specifics.

  9. #9
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for you reply as well. This is a nice one, but What do I do when a user wants to edit a contact? Dynamically generate input fields? And yeah, I can generate input fields dynamically but how am I supposed to retrieve data from them and perform a mysql record update at the same time deleting some records if user removes phone numbers during editing process for example.. :s
    As oddz has suggested, this is a pretty usual 1:n scenario. To keep the database integrity, I suggest using InnoDB engine and foreign keys. That way, when you delete (or update) a user, all contacts/addresses etc will be automatically deleted by MySQL without you needing to bloat your PHP with dozens of queries.

    http://dev.mysql.com/doc/refman/5.1/...nstraints.html

  10. #10
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for you reply as well. This is a nice one, but What do I do when a user wants to edit a contact? Dynamically generate input fields? And yeah, I can generate input fields dynamically but how am I supposed to retrieve data from them and perform a mysql record update at the same time deleting some records if user removes phone numbers during editing process for example.. :s
    Well, the simplest solution would be to have a single page for adding phone numbers, single page for editing and removing.

    If you want to somehow allow users to add/delete the numbers on a single page, you will need to use some javascript for expanding additional input fields.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •