2
In my database in the table paginas
I have the fields pagina_1
, pagina_2
and pagina_3
representing the three pages of my website.
In these fields I will insert the page views as below.
In the code of my "page one", for example:
<?php
$result = mysql_query( "SELECT pagina_1 FROM paginas" )
or die ( mysql_error() );
$row = mysql_fetch_assoc( $result );
$visualizacoes = $row['pagina_1'];
$visualizacoes_mais = $visualizacoes + 1;
$sql = mysql_query( "UPDATE paginas SET pagina_1 ='$visualizacoes_mais' " )
or die ( mysql_error() );
...
?>
With this code I get that every time a page is accessed, the views are incremented.
Is it a correct way to record views of each page? I know this is a relative question, but deep down I want to know if there is another way or if it is like this: I will have to create a field for each page that my site has, be it 10, 100 or 1000 pages?
As for the Assoc and array, the difference is that with
assoc
(array associative) Voce uses$row['nomedocampo']
, and with array common can only use index:$row[2]
, for example.– Bacco
Dude, I was here editing to answer your questions, but your questioning has already made me realize that I can actually create a unique table for this regardless of users. In my mind, at first, users entered the subject because it was a restricted access page, so I would add up the views of each user to find the total number.
– I Wanna Know
I hesitated to say create two hundred fields because I was already using the page field to handle the number of clicks of a Ubmit input.
– I Wanna Know
Anyway, once you get a better view of how you want to do it, edit the question with as many relevant details as possible, which makes it easier for me or another user to help you.
– Bacco
Bacco, I posted the question the way I’m doing it.
– I Wanna Know