Hope this is clear and concise! I have a view article page and every time you land on the page then I have a query that runs an update using sql. Now the problem is everytime the script is run it counts one hit as 2. For example if an article has been viewed 4 times. Next time you land on the page it shows the page has been seen 6 times instead of 5. Here is my code below for the view_article page:
Code: Select all
<body bgcolor="#000000">
<div id="site_div" align="center">
<div id="wrapper_div">
<!-- header -->
<?php
include 'header.php';
?>
<!-- header -->
<div id="main_nav">
<div id="link1_div"><p class="link1_class"><a href="index.html" class="link1_class">All Articles</a></p></div>
<div id="link2_div"><p class="link2_class"><a href="index.html" class="link2_class">Reviews</a></p></div>
<div id="link3_div"><p class="link2_class"><a href="index.html" class="link2_class">Previews</a></p></div>
<div id="link4_div"><p class="link2_class"><a href="buys.php?lightbox[width]=700&lightbox[height]=400&lightbox[modal]=true" class="link2_class lightbox">Videos</a></p></div>
<div id="link5_div"><p class="link2_class"><a href="rents.php?lightbox[width]=700&lightbox[height]=400&lightbox[modal]=true" class="link2_class lightbox">News</a></p></div>
<div id="link6_div"><p class="link2_class"><a href="index.html" class="link2_class">Podcasts</a></p></div>
<div id="link7_div"><p class="link2_class"><a href="index.html" class="link2_class">Contact Us</a></p></div>
<div id="link8_div"><p class="link2_class"><a href="index.html" class="link2_class"></a></p></div>
</div>
<div id="sub_nav">
<div id="sub_nav_div">
<p class="filter_by_class">FILTER BY: <a href="index.php" style="color:#21a8f7; text-decoration:underline">All</a> <a href="xbox360.php">Xbox 360</a> <a href="#">PS3</a> <a href="#">Wii</a> <a href="#">PC</a> <a href="#">PSP</a> <a href="#">DS</a><a href="#">Mobile</a><a href="#">Older Platforms</a></p></div>
</div>
</div>
<div id="content_div">
<div id="content_spacer">
</div>
<!-- TRACK PAGE VIEWS -->
<?php
//DATABASE CONNECTION
include_once 'dbc.php';
$id = $_GET['id'];
mysql_query("UPDATE articles SET views = views +1 WHERE idarticles='$id'");
// TrACK PAGE VIEWS
// MAIN CONTENT
if(isset($_GET['id']) && is_numeric($_GET['id']) ) {
$query = "SELECT * FROM articles WHERE idarticles= {$_GET['id']}";
if($r = mysql_query($query)) {
$row = mysql_fetch_array($r);
echo "
<div id=\"main_article_div\">
<div id=\"top_blue_content_div\"> {$row['article_type']}</div>
<div id=\"image_main_content_div\"><img src=\"{$row['article_big_image']}\" width=\"200\" height=\"112\" alt=\"main_article_image\" /></div>
<div id=\"content_area\"><p class=\"main_content_title_class\">{$row['article_title']}
<div id=\"addthisspacer\">
<!-- AddThis Button BEGIN -->
<div class=\"addthis_toolbox addthis_default_style \">
<a class=\"addthis_button_facebook_like\" fb:like:layout=\"button_count\"></a>
<a class=\"addthis_button_tweet\"></a>
<a class=\"addthis_counter addthis_pill_style\"></a>
</div>
<script type=\"text/javascript\" src=\"http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4d1d4fb34dc87309\"></script>
<!-- AddThis Button END -->
</div>
</p>
</div>
</div>
";
}
}
?>
<!-- MAIN CONTENT ENDS -->
</div>
<div id="lower_content_div">
<!-- THIS IS WHERE THE MAIN ARTICLE/COMMENTS STARTS -->
<?php
//include 'dbc.php';
if(isset($_GET['id']) && is_numeric($_GET['id']) ) {
$query = "SELECT * FROM articles WHERE idarticles= {$_GET['id']}";
if($r = mysql_query($query)) {
$row = mysql_fetch_array($r);
echo "
<div id=\"left_lower_content\" class=\"break-word\">
{$row['actual_article']}
</div>
";
}
}
?>
<!-- THIS IS THE END OF THE MAIN ARTICLE/COMMENTS QUERY -->
</div>
<div id="footer_div">
<div id="footer_1"></div>
<div id="actual_footer">
<div id="top_footer_div">
<div id="top_footer_div_left"><a href="login.php?lightbox[width]=396&lightbox[height]=200&lightbox[modal]=true"><img src="images/rent-or-buy-2-logo_small2.png" width="260" height="39" alt="small_logo" class="small_logo_class" /></a></div>
<div id="top_footer_div_right">
<div id="login_register_div_2">
<p class="logintext"><a href=""><img src="images/rss_icon.png" width="16" height="16" alt="rss_icon" /></a></p><p class="logintext"><a href="http://www.twitter.com"><img src="images/twitter_icon.png" width="16" height="16" alt="twitter_icon" /></a></p><p class="logintext"><a href="http://www.youtube.com"><img src="images/youtube_icon.png" width="38" height="16" alt="youtube_icon" /></a></p><p class="logintext"><a href="http://www.facebook.com"><img src="images/facebook_icon.png" width="16" height="16" alt="facebook_icon" /></a></p>
</div>
</div>
<div id="search_div2">
<form action="#" method="post" name="search">
<input type="text" value="Search!" class="formimage" />
<INPUT TYPE="IMAGE" src="images/search_bar_button.jpg" BORDER="0" style="padding:0" class="formbutton">
</form>
</div>
</div>
<div id="actual_footer_bottom_section">
<div id="actual_footer_bottom_section_top"></div>
<div id="actual_footer_bottom_section_top_links"><a href="index.php">All Articles</a> | <a href="#">Reviews</a> | <a href="#">Previews</a> | <a href="#">"Buys"</a> | <a href="#">"Rents"</a> | <a href="#">Videos</a> | <a href="#">News</a> | <a href="#">Games</a> </div>
<div id="actual_footer_bottom_section_bottom">
<p class="actual_footer_bottom_section_paragraph">Design By: Felix Henriques | Created By: Felix Henriques | Copyright 2010 Buy Or Rent Games</p></div>
<div id="actual_footer_bottom_section_top"></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>pickle | Please use [ syntax=php ], [ syntax=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: