The following code connect to my db, graps the counter field value which holds an integer that represents the total amount of hits in index.pl
my $db = ( $ENV{'SERVER_NAME'} !~ /varsa/ ) ? DBI->connect('DBI:mysql:pneumatika;localhost', 'root', '***** +**', {RaiseError=>1}) : DBI->connect('DBI:mysql:18177_pneumatika;fdb1.runhosting.com' +, '18177_pneumatika', '*****', {RaiseError=>1}); $select = $db->prepare( "SELECT counter, host FROM guestlog" ); $select->execute; my $pagecounter; while( $row = $select->fetchrow_hashref ) { $pagecounter += $row->{counter} unless ($row->{host} eq "varsa); }
What must be add to this code that is able to save each unique webpage counter at a specific mysql table field adding 1 every time and also do this for every new page i create because the number of the pages aren't fixed plz post it here.

The code also has to be able to modify mysql table 'guestlog' and add a new table field every time a new page is loaded that doesnt have a corresponding counter by means of table field named as the page itself holding an integer value.

For example if a user opens index.html then connect to mysql and to table counter, find index filed add 1 to it!

if a page named hello.html its loades try to add 1 to its table filed too if it does not exist, alter the table structure by adding 1 more field with the same name of the webpage and then add 1 too.

For example it the name is hello.html then the corresponing table filed has to be 'hello' with an integer value of one.

That way one can use the code in every new webpage he creates without dropping and creating a bigger mysql table.

is this possible?

In reply to Making an automatic counter adder for all webpages by Nik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.