|
-
Jun 10th, 2002, 12:46 PM
#1
Thread Starter
Addicted Member
making counters
I have a counter made right now but I'm wondering if it is the most effecient way of making one.
Should I be making the counter table based or should I just keep incrementing from a text file? What is the best, most effecient way of doing it? I'm using a table now but that table will get so huge.
-
Jun 10th, 2002, 12:49 PM
#2
Stuck in the 80s
If you're just storing the number of times the page has been viewed, use a flat (.txt) file to save the number.
Open it, get the value, increment it, write the new value, print the value to the page.
I wouldn't use a MySQL database for it.
-
Jun 10th, 2002, 12:56 PM
#3
Fanatic Member
man!! If I hadnt cleared off my server I would have a nice zip file that you could view to see how I wrote mine.
I used a database that would make a new table every month so I could easily track the referer, the ip, browser, the page they were viewing, etc. etc. etc.
I also had a really nice admin side to it too. I have a copy of it at my home, but I wont be there until August 8th.
What a bummer!
-Matt
-
Jun 10th, 2002, 01:06 PM
#4
Thread Starter
Addicted Member
thats cool but you didn't run into any lag because your db got so big? I got counters made from tables and its pretty helpful, I track time/date, event they're viewing and can make nice reports from it but I'm just concerned that its going to get too massive in the future.
-
Jun 10th, 2002, 01:18 PM
#5
Fanatic Member
i never ran into a size problem. And I would find it more annoying to have to open a file read it, write to it and then close it.
-
Jun 10th, 2002, 01:25 PM
#6
Stuck in the 80s
I thought he wanted a simple counter, not a monthly statistic thing. In which case I would still stand on my case that a file would be better. But okay...
-
Jun 10th, 2002, 09:30 PM
#7
Fanatic Member
Yeah, I dont mind flat files and all but they are just a waste of time (or so I think). Why would you bother worrying about opening, grabing the text, exploding it to place the data into the correct variables, then displaying, all so you can then write it back so the most recent data is on top, and close up the file?
It just seems like too much work for a counter, but maybe its not.
-
Jun 10th, 2002, 10:03 PM
#8
Stuck in the 80s
PHP Code:
$f = fopen('file.txt', 'a+');
$c = fread($f, filesize($f));
$c++;
fwrite($f, $c);
fclose($f)
echo $c;
Seems alot easier to me than:
PHP Code:
$db = mysql_connect("host", "user", "pass");
mysql_select_db("main",$db);
$c = mysql_fetch_array(mysql_query("SELECT * FROM count LIMIT",$db));
$c++;
mysql_query("Update count SET num='$c' WHERE id='0'");
echo $c;
I guess it's just me, though.
-
Jun 10th, 2002, 10:06 PM
#9
Fanatic Member
im pretty sure you can shorten that to:
PHP Code:
$db = mysql_connect("host", "user", "pass");
mysql_select_db("main",$db);
$query = mysql_query("Update count SET num=num+1");
// Read new value and display it after that
-
Jun 10th, 2002, 10:11 PM
#10
Stuck in the 80s
You shortened it by one line and also neglected two lines I had in there at are needed. I still think it's far easier to use a flat file. Don't go into overkill over something so simple.
-
Jun 10th, 2002, 10:16 PM
#11
Fanatic Member
Originally posted by The Hobo
You shortened it by one line and also neglected two lines I had in there at are needed. I still think it's far easier to use a flat file. Don't go into overkill over something so simple.
Just out of curiousity what two lines are needed?
-
Jun 10th, 2002, 10:17 PM
#12
Stuck in the 80s
// Read new value and display it after that
-
Jun 10th, 2002, 10:19 PM
#13
Stuck in the 80s
If we want to shorten things, we could get rid of a line here too:
PHP Code:
$f = fopen('file.txt', 'a+');
$c = fread($f, filesize($f)) + 1;
fwrite($f, $c);
fclose($f)
echo $c;
So compact it fits in your purse!
-
Jun 10th, 2002, 10:25 PM
#14
Fanatic Member
lol, i know. I was just too lazy to write that line of code. If you want me to all it is, is this:
PHP Code:
echo mysql_result(mysql_query("select num from count order by id desc limit"),0,"num");
-Matt
-
Jun 10th, 2002, 10:27 PM
#15
Stuck in the 80s
It may only be one line longer, but mine is plenty columns shorter
-
Jun 10th, 2002, 10:28 PM
#16
Fanatic Member
-
Jun 10th, 2002, 10:33 PM
#17
Stuck in the 80s
what do I win? free pass to hooters or the likes, eh?
-
Jun 10th, 2002, 10:44 PM
#18
Fanatic Member
Your prize is nothing of sentimental value but the knowledge you have exchanged over this thread along with the many others you have started, posted in, and solved.
-
Jun 10th, 2002, 10:45 PM
#19
Stuck in the 80s
Oh. Not even a certificate or anything?
-
Jun 10th, 2002, 10:49 PM
#20
Fanatic Member
If I had fireworks installed on my computer I would give you one, but im on a laptop in Texas 1300 miles away from my own computer ( )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|