I don't really know how to explain this easily. I guess I will layout the project I am trying to do, and the problem I am having with it, and maybe someone could explain it better to me.
I am trying to build an online food journal for a fitness/nutrition company. I have a form page made out that will allow their clients to input their eating habits for the day.
http://befit4riding.com/food_journal.html
I was thinking that I would have a db for each client, and each day would be a new table. I need to be able to store each day of data and keep it accecible for a later time. I also need to email the data to the company each time new data is submitted. Turns out, the server I am working on only allows 1 db. So how do I organize the tables so that they are all under the same client, but I can have multiple clients? Is there some kind of 'sub-table' (db/table/sub-table)? If I am not explaining myself adequately, please ask some specifics and I will be happy to try again.
notes on the page. I didn't have it automatically input the date, because sometimes people don't update everyday, so they need to be able to come in and put in multiple days at once, but have the correct date for each one. Eventually I might put in a calendar function, but I would have to learn that one and trying to just get this going first.
Thanks.
Unless you have two separate applications, you don't need two databases. You can even have different applications share 1 db by prefixing tables. eg: app1_table, app2_table
I think what you want to do is create relationships between your tables. (no db's don't have sub tables). Since your working with a relational database, you can create relationships between tables that simulates "sub-tables".
You don't need a db for every client, or table for every client. This is very inefficient.
What you want is a single table for your clients. Each client should have a unique index.
Then you want another table storing information about clients. Each info has a unique index, and another index with a value that corresponds to the index in the client table. This lets you know that this data is for that client.
If you need different data for different days stored, just create a column where you save a timestamp in your client data table.
It would be easier to understand if you have a good book on relational databases to guide you.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
> I in no way was trying to promote the site, I just linked it to give a reference for what I was trying to do. If this is a violation, could one of the mods please remove the link from my post?
I cannot speak for the other mods, but I am more lax about this rule in the web development forums. What really pisses me off is when people post in the Internet marketing forums questions like, "Please give me suggestions on how I can promote my website www.mysite.com". It's also very hard to have candid discussions related to Internet marketing with the constant fear that everyone knows who you are and your competitors are there to see what you're doing and how you're doing it ... a general rule of not mentioning your site allows much more unbiased conversations because people are free to share their experiences about what worked and what didn't with regards to making money, advertising, etc,.
cscgal
The Queen of DaniWeb
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
Ok, after doing some reading, I think I got an idea of how to structure the table, client_logs. I can have a row for the client, with a specific date, and then all the fields from the page for that date. Then when I want to pull up a specific day of log entry, I can query the db with
SELECT * FROM client_logs WHERE client='value', date='value'
That is what I got from my research on this, but it looks like digital-ether, has a slightly different method, which sounds like it might save time in the long run. Any suggestions/critiques/ways to do it better on this approach?
Thats pretty much the same as what I mentioned.
Do you have a separate table for clients?
So you're query would be like: SELECT * FROM client_logs WHERE client={clientid}, date='{timestamp}' LIMIT 1
where the {clientid} is the index of the client's row in the clients table and {timestamp} is any date/time format.Note the LIMIT 1. It's good practice to let the DB know that you only want a single entry. The reason is that the DB stops iterating through its index as soon as it reaches the first valid row. Otherwise, it goes through all rows. If you have something like 100 000 rows, this makes a huge difference.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101