By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,584 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,584 IT Pros & Developers. It's quick & easy.

Altering MySQL table structure after it's created / populated using PHP

P: n/a
I have written a database that counts the number of times a file has
been accessed, so I can then later display the results on what is "hot" and
what is not. At the moment all it does is count the total hits, it does
not log per-month the results, which is what I'd like to try.

So suppose I have a database that on initial creation (in month May) looks
like:

ID URL Accessed
1 whatever1 1
2 whatever2 4
3 whatever3 17

However, in June I decide to add to the database another file to download
in the database, so for June now it becomes:

ID URL Accessed
1 whatever1 4
2 whatever2 3
3 whatever3 9
4 whatever4 21

But now when I want to display the results for May and June, how do I
display Mays results (marked with "x" below) as there is no ID4 field as
there was no such file to download in that month?

ID URL May June
1 whatever1 1 4
2 whatever2 4 3
3 whatever3 17 9
4 whatever4 x 21

What I'm getting at, is that every time I add a file to the table, it will
alter the table structure, so what to do with the previous months where
there will not be that file data.

Dariusz
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In message <Q_*******************@wards.force9.net>, Dariusz
<ng@lycaus.plusYOURSHIT.com> writes
I have written a database that counts the number of times a file has
been accessed, so I can then later display the results on what is "hot" and
what is not. At the moment all it does is count the total hits, it does
not log per-month the results, which is what I'd like to try.

So suppose I have a database that on initial creation (in month May) looks
like:

ID URL Accessed
1 whatever1 1
2 whatever2 4
3 whatever3 17

However, in June I decide to add to the database another file to download
in the database, so for June now it becomes:

ID URL Accessed
1 whatever1 4
2 whatever2 3
3 whatever3 9
4 whatever4 21

But now when I want to display the results for May and June, how do I
display Mays results (marked with "x" below) as there is no ID4 field as
there was no such file to download in that month?

ID URL May June
1 whatever1 1 4
2 whatever2 4 3
3 whatever3 17 9
4 whatever4 x 21

What I'm getting at, is that every time I add a file to the table, it will
alter the table structure, so what to do with the previous months where
there will not be that file data.

Dariusz


Try a different count table structure. If you add a column to hold the
month (or month & year) to the table, then you won't have to keep
changing the structure of the table. You can simply either update the
existing row, or insert a new one for the first count for a given month
or month & year.
--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #2

P: n/a

"Five Cats" <ca*******@[127.0.0.1]> escreveu na mensagem
news:Yp**************@[127.0.0.1]...
In message <Q_*******************@wards.force9.net>, Dariusz
<ng@lycaus.plusYOURSHIT.com> writes
I have written a database that counts the number of times a file has
been accessed, so I can then later display the results on what is "hot" andwhat is not. At the moment all it does is count the total hits, it does
not log per-month the results, which is what I'd like to try.

So suppose I have a database that on initial creation (in month May) lookslike:

ID URL Accessed
1 whatever1 1
2 whatever2 4
3 whatever3 17

However, in June I decide to add to the database another file to download
in the database, so for June now it becomes:

ID URL Accessed
1 whatever1 4
2 whatever2 3
3 whatever3 9
4 whatever4 21

But now when I want to display the results for May and June, how do I
display Mays results (marked with "x" below) as there is no ID4 field as
there was no such file to download in that month?

ID URL May June
1 whatever1 1 4
2 whatever2 4 3
3 whatever3 17 9
4 whatever4 x 21

What I'm getting at, is that every time I add a file to the table, it willalter the table structure, so what to do with the previous months where
there will not be that file data.

Dariusz


Try a different count table structure. If you add a column to hold the
month (or month & year) to the table, then you won't have to keep
changing the structure of the table. You can simply either update the
existing row, or insert a new one for the first count for a given month
or month & year.
--
Five Cats
Email to: cats_spam at uk2 dot net


Why don't you do a SQL query that only selects the fields that are not null
in the mont you want. Someting like :
select ID,URL,MyMonth where MyMonth!='x';

Vitor
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.