android - Query about sync database columns with days of the week -
i'm doing android studio project , i'm using sqlite database. in app allow user enter calorie intake day.
the database have corresponding columns hold users calorie intake day. mondays calorie intake saved in monday_cal column.
edit: app has 2 tables in database; 1 stores user details, calories needed , mon_cal etc. 2 stores product details , calories amount. user selects product , calories added total.
for example,
my question how make column in calories being entered change match days
ex:
when monday on column being selected changes monday_cal tuesday_cal.
my original plan simple if statement , presumed there call on (clock or calender) cant find material or tutorials on area think may searching wrong phrase? , if way not possible there other alternatives.
you don't want storing individual days fields in user table. if you're storing mon-sun, you're limiting ever keeping 7 days history per person.
a better solution separate calorie intake own table, related user table, this:
create table calorie_intake( user_id integer not null, intake_date date, calories integer, primary key(user_id, intake_date), foreign key (user_id) references users(id) );
this schema uses id
field of users
table create relationship. find users calorie intake specific day execute query similar following:
select calories users u inner join calorie_intake on u.id = i.user_id u.id = 1 , intake_date = '2015-04-10';
which give calorie intake user id 1
, on april 10th, 2015.
this process of creating relationships , moving away 'all data in 1 table' design called normalisation, there plenty of info out there on subject , if going doing database work @ all, shooting in foot not being aware of concept. heres link started