Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Making an automatic counter adder for all webpages

by Fletch (Bishop)
on Dec 22, 2007 at 15:04 UTC ( [id://658653]=note: print w/replies, xml ) Need Help??


in reply to Making an automatic counter adder for all webpages

Altering your table structure on the fly like that is just inane. You want to have a table with a row for each page with the counter on that.

The cake is a lie.
The cake is a lie.
The cake is a lie.

  • Comment on Re: Making an automatic counter adder for all webpages

Replies are listed 'Best First'.
Re^2: Making an automatic counter adder for all webpages
by Nik (Initiate) on Dec 22, 2007 at 16:00 UTC
    Well, that is what i would have done if i knew aprioari how many pages i would create. Then i would count them and create a mysql table with as many fields as the amount of total web pages.

    But what happens if you don't know how many pages you are about to make, or you do but then you decide to make some more?

    I beleive the idea of altering the table structure on the fly is great, so you dont have to mess with mysql all the time, altering tables, or dropping them and create new ones...Can you help me make script?

      Don't you think there's a contradiction here?
      I beleive the idea of altering the table structure on the fly is great, so you dont have to mess with mysql all the time, altering tables, or dropping them and create new ones...
      (Bold is mine) You either think that altering the table is a great idea, or that it's a complete mess. And you're right in the second case.

      What Fletch meant<stroke>, I think,</stroke> is that you should have a table with two columns: one for the name of the page, and the other for the associated counter. Something like this:

      +----------+---------+ | pagename | counter | +----------+---------+ | home | 123 | | page_1 | 22 | | page_2 | 16 | | credits | 2 | | policy | 1 | +----------+---------+
      This way, each new page is just a new record in this table, which you can do with a simple INSERT.

      Hey! Up to Dec 16, 2007 I was named frodo72, take note of the change! Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Io ho capito... ma tu che hai detto?
        Yes indeed this is very clear and better.

        But in order to increase a counter for a specific page or create it first and then populate it, the script must know which webpage just loaded for example page_5.html and extract just the filename without the dot and extension.

        How to do this? The best i can do is this:

        $pagename = "something that tells me what si the name of the currnt sc +ript running, just its filename"; if ( $pagename is an already actual field inside table 'counter' then +) { $select = $db->prepare( "SELECT pagename, pagecounter FROM counter +s" ); $select->execute; } else { $select = $db->prepare( "INSERT INTO counters (pagename, pagecount +er) VALUES (?, ?)" ); $select->execute( $pagename, 1 ); my $pagecounter; while( $row = $select->fetchrow_hashref ) { $pagecounter += $row->{pagecounter} unless ( $row->{host} eq "&#92 +5;&#943;&#954;&#959;&#962;" ); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://658653]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found