Skip to main content
Known Participant
July 11, 2011
Answered

how to keep track of views of a particular mysql entry

  • July 11, 2011
  • 1 reply
  • 641 views

I have a dynamic website through php and mysql. How do I get my website to keep track of the amount of views each entry got (and for the amount of views to be recorded in my mysql table? Is there an easy way to do this with dreamweaver?

This topic has been closed for replies.
Correct answer

i do have a column for views but i have do not know how the results would be inputed.

how do i use that "update statement" you mentioned to input increment view amounts in my column?

table_name has column for views.

page is a column in table that is used to dynamically display content based on title in URL parameter ie

website.com/?page=home

website.com/?page=about_us

etc.

Use query to update views+1 where page = the URL parameter that is entered into address bar to display the dynamic page content.

$page = "-1"; if (isset($_GET['page'])) { $page = $_GET['page'];

$query_hits = sprintf("UPDATE table_name

SET views = views+1

WHERE page = %s", GetSQLValueString($page, "text"));

$hits = mysql_query($query_hits, $connection) or die(mysql_error());

}

best,

Shocker

1 reply

Participating Frequently
July 11, 2011

>Is there an easy way to

>do this with dreamweaver?

I don't know of a server behavior that will do this, but it's very easy to code. Everytime you retrieve the item for viewing, you also issue an update statement that increments a counter in the table. Does your 'item' table already have a column for counting views? That would probably be a good place to put it, but it's hard to say without knowing more about your database design.

YWSWAuthor
Known Participant
July 11, 2011

breqent,

i do have a column for views but i have do not know how the results would be inputed.

how do i use that "update statement" you mentioned to input increment view amounts in my column?

I am a beginner to php and mysql and have some difficulty venturing farther than (or even deciphering) dreamweaver's php code.

thanks,

YWSW

YWSWAuthor
Known Participant
July 11, 2011

i do have a column for views but i have do not know how the results would be inputed.

how do i use that "update statement" you mentioned to input increment view amounts in my column?

table_name has column for views.

page is a column in table that is used to dynamically display content based on title in URL parameter ie

website.com/?page=home

website.com/?page=about_us

etc.

Use query to update views+1 where page = the URL parameter that is entered into address bar to display the dynamic page content.

$page = "-1"; if (isset($_GET['page'])) { $page = $_GET['page'];

$query_hits = sprintf("UPDATE table_name

SET views = views+1

WHERE page = %s", GetSQLValueString($page, "text"));

$hits = mysql_query($query_hits, $connection) or die(mysql_error());

}

best,

Shocker


perfect.

shockingly simple