New deals posted everyday, starting Black Friday and running through the holiday season! No hassles, no lines - just awesome savings on art, deviantWEAR, Premium Memberships and more!

Artist's Comments
counter.php
While I am by no means a programmer, I do get in touch with code every once in a while. Be it clumsy attempts in writing my own userscripts to customize dA, be it modding userscripts to further enhance and personalize my experience with websites like dA, be it copying lines of code off tutorial sites to enhance the experience of websites I create, be it HTML and CSS "code" when writing websites in the first place. But this is as far as it goes. This few lines of code above I wrote while following a tutorial from 3D Buzz some time ago, trying to get into the php stuff a bit. What does it do? Simple, it's a webcounter, telling you how many people visited this page. Info Editor: UltraEdit-32 10.10b (with customized colours) Visual Style: b0se Classic Final by ~b0se This is a submission for and tribute to ~CodeIsArt |
Details
October 18, 2007
42.3 KB 42.3 KB 900×700 Statistics
10
0 651 (0 today) 0 (0 today) Share
Link
Embed
Thumb
|
Comments
Very usefull code tho
--
I am Rich aka Tricks found more or less everywhere artistic
dA number #465,411
Founder of #MasterCSS
And thanks, I'll see what I can do.
--
█ ¢creative
--
I am Rich aka Tricks found more or less everywhere artistic
dA number #465,411
Founder of #MasterCSS
Yep, tried it already, looks promising!
--
█ ¢creative
Nice one hon
--
Zeta B.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
* Why define $query, when you could just put it into the function call?
* Why use a database, which can be unreliable, when a text file could suffice? Also, running two SQL queries every time the page is viewed puts unnecessary strain on the DB under heavy load.
* You could also use the session to remember a viewer and prevent them from racking up the count just by pressing refresh.
* Why kill the whole PHP page when an SQL error occurs for the page view counter? This seems over-kill when the rest of the page may work fine or not even use the database. I would place the counter in a function, and just exit the function on an error so that people could still use the site, even if the counter was not working.
* You shouldn't do "SELECT *" it's extra load on the server, always select just the fields you need.
* The second query could be built directly off of the first one, like thus:
$views=mysql_fetch_row(mysql_query("SELECT `num_views` FROM `counter`;",$connection))[0]++.";";
mysql_query("UPDATE `counter` SET `num_views`=$views;");
This would replace lines 6-13 with two lines, and I'm certain there's an even more compact way to do that in PHP.
Thanks very much for your time and effort to submit your code, I've enjoyed looking at it
$views=mysql_fetch_row(mysql_query("SELECT `num_views` FROM `counter`;",$connection))[0]++;
mysql_query("UPDATE `counter` SET `num_views`=$views;");
I'll do my best to incorporate these into a possible future version, and then maybe make a direct comparison. Should be interesting. For now I can only say, I'm probably much more of a newb in PHP than you might think. But who knows, I'm always trying to learn.
Again, thanks!
--
█ ¢creative
Previous Page12Next Page