PDA

Click to See Complete Forum and Search --> : The best way to store this information with php?


wwwfilmfilercom
Mar 31st, 2008, 10:09 AM
Hi,

I would like to store some data for each day of the week. My user will click on an item and assign that to period of a particular day. There can be any number of items for each day, for each period.

I'm thinking that I will use sessions to store this information as they are relatively easy to save data to, and they will clear if the user exits the browser (in simple terms). The data is not anything vastly important, so I don't plan on saving it to the database. And since it can be saved [to the database] if the user wishes , I don't plan on saving to a cookie file either.

My question is whether this is the best way to store the data? For example I was considering that I could have 7 sessions for each day of the week and then in each one have 3 arrays (morning, afternoon, evening). Then whatever the user adds I will push onto the end of the correct array in the correct session..

Does that make sense? Is it possible? I know how to set the session but how do I make each one include 3 arrays? That's the bit I'm mostly confused with.

Hope you can help, many thanks!:thumb:

dclamp
Mar 31st, 2008, 10:48 AM
I think that you should just save them all in the database. that would make it easier.

Im not really sure how you would make a session into 3 arrays. If you must you could have 28 sessions, one for morning afternoon evening, for every day of the week. But this is a really bad way to do it

wwwfilmfilercom
Mar 31st, 2008, 10:55 AM
I agree, I don't like the idea of having 28 sessions flying around, but is there a better way than just using databases? This information can be saved later to a database but at the start it just needs to go into a 'temporary db' of sorts.

Also: how would I store it properly in a database?

There are definitely 7 days for each week. Each day will be split into 3 (maybe 4 later on). However, each part of the day can have any number of items linked to it. So I want to come up with a solution that doesn't mean I have to write to various different tables just store the data.

dclamp
Mar 31st, 2008, 11:24 AM
well you can create a temporary table in mysql. might want to look into that.

But as to storing it, you want one table called "events" (or something) and in the table you will have fields "day" (mon/tues/wed..), "time" (morn/afternoon...), "member" (or another way to tell people apart).

from there you will load all the members events from each day.

SELECT * FROM `events` WHERE day='Monday' AND time='afternoon'

visualAd
Apr 1st, 2008, 04:49 AM
Hi,

I would like to store some data for each day of the week. My user will click on an item and assign that to period of a particular day. There can be any number of items for each day, for each period.

I'm thinking that I will use sessions to store this information as they are relatively easy to save data to, and they will clear if the user exits the browser (in simple terms). The data is not anything vastly important, so I don't plan on saving it to the database. And since it can be saved [to the database] if the user wishes , I don't plan on saving to a cookie file either.

My question is whether this is the best way to store the data? For example I was considering that I could have 7 sessions for each day of the week and then in each one have 3 arrays (morning, afternoon, evening). Then whatever the user adds I will push onto the end of the correct array in the correct session..

Does that make sense? Is it possible? I know how to set the session but how do I make each one include 3 arrays? That's the bit I'm mostly confused with.

Hope you can help, many thanks!:thumb:
Will users be sharing this data? Sessions are ideal if you want to store data on a temporary basis (i.e: for a browser session). Why do you talk about multiple sessions? Why not store an array in the session variable containing each day?

$_SESSION['days'] = array(0 => 'Monday',1 => 'Tuesday',2 => 'Wednesday',3 => 'Thursday', 5 => 'Friday', 6 => 'Saturday');


Obviously you can nest as many arrays as you like. Sessions are stored as files and associated with the users through a session identification (stored as a cookie on the browser). The downside is that any data in the file gets loaded into memory so if you have more 1MB of data and 500 concurrent connections you will be using 500MB memory.

So, although the overhead of making a connection and querying the DB may be greater. It may be a better solution if you are storing large amounts of data.

wwwfilmfilercom
Apr 1st, 2008, 04:16 PM
The downside is that any data in the file gets loaded into memory so if you have more 1MB of data and 500 concurrent connections you will be using 500MB memory.

Do you mean on the users computer or the server?

Each 'day' will have 3 'times' and each 'time' can hold any number of 'itemids' which will just be integers relating to a database table. So on the face of it I don't think this equates to 'a lot of data' - I'm not sure however, maybe you can advise more on this.

Users can then save this data - to the database, and only then could it be shared, or accessed by other users.

Nesting the arrays seems to make sense, although how would I structure it? Would I have one session (days) and within that have the arrays or different sessions for different days or - what combination would work best?

Thanks for the help,

penagate
Apr 1st, 2008, 07:44 PM
Sessions are stored on the server, so memory usage is on the server.

I also don't think that you are likely to store a lot of data (although I don't know anything about your users). However, the data structure you describe lends itself very well to a relational database.

Temporary tables are not a good idea as they are destroyed when the connection is closed. Thus temporary tables will only last for one script execution. If you were to use persistent connections it would be hit and miss whether the right temporary tables were available as the connections are allocated from a pool. Use a regular table — this way you don't have to worry about sessions except for login data, which is as it should be.

wwwfilmfilercom
Apr 2nd, 2008, 01:43 AM
I'm going to go with your suggestion Penagate! Thank's a lot!

> Thanks to everyone who replied!