2

I'd like to store all IP's used by a user, for every user.

So, I could figure out where they are coming from, if they switch a lot. If all of a sudden they are using a new one, etc.

I know to store it as a number in MySql so it is smaller data, but how do I store let's say 100 IP's for each user? I can do it in MySQLi if it is better to use it.

Thanks!

Alan1993
  • 21
  • 1

2 Answers2

3

You are correct on using a database for this. With so many items best to use database. I would setup at least two tables for this. One table that stores the users. Then the next table to store the IP address. This table would also have a key that would reference the user table. IE each row in your user table will have _ID. Then in IP table have a column like "userKey" and then reference that same ID but this time around its not your primary key.

maebe
  • 553
  • 1
  • 6
  • 18
  • If I have like 10000 users with let's say 100 IP's, that is 1000000 rows to add. Is that okay? – Alan1993 Feb 29 '12 at 06:41
  • Sure, your database can be as big as you want. You only run into issues with database size if you have it in your apk and its over 1mb (it will be compressed) but really the database wont take up much space. My current app has one table that has ~6 columns and 500+ rows. Being 1 of 6 tables (the biggest) and yet still only 56kb. If your worried about size allow storing app on sd card and don't give it a second thought :D – maebe Feb 29 '12 at 06:46
0

Create two tables like this

user table
user_id
username
otherFields

UserDetails
user_id
IpAddress
someOtherFields

then you can join these two table based on user_id to get All the ipAddress used by a particular user.

Naveen Kumar
  • 4,543
  • 1
  • 18
  • 36