Hey guys i would like to have a No. of views on each article , i came across the following script on SO:
http://stackoverflow.com/a/4762559/4381665
Now how would i integrate this into bolt ??
How do i integrate this into bolt though ?? can somebody tell me one simple way of doing this ??
Where would the script go ?? I believe the login would be something like:
Every article would have a additional field named say "views".
Whenever an article is clicked is clicked this script is run and the database is updated .
Am i thinking the right thing ? Please guide me .
How to add no of views in bolt ??
Moderator: General Moderators
Re: How to add no of views in bolt ??
What have you tried so far? Where are you running into trouble?
Re: How to add no of views in bolt ??
@celauran ! Heyyo Buddy , when i asked the question , i was quite blank in my mind as to how to go about implementing this feature... anyways , what i actually did was go and build a vanilla PHP tinyblog with a feature of actually counting views and actually managed to build it , it was quite fun ... (i did this just so i could create a simplistic example and then implement this feature in BOLT)
LINK HERE http://peckingatcode.net/Tiny_Blog/
The code in the article_blog.php where the views get counted looks like following:
Now i need to implement this in bolt
Thanks.
LINK HERE http://peckingatcode.net/Tiny_Blog/
The code in the article_blog.php where the views get counted looks like following:
Code: Select all
<?php include('header.php'); ?>
<?php
$article_id = $_POST['article'];
$db = new PDO('mysql:host=localhost;dbname=peckinga_tinyblog', 'peckinga_general', 'gautam');
$sql = 'SELECT id,blog_title, blog_body, views FROM tinyblog where id="'. $article_id .'" ';
$retval = $db->query($sql);
// Update views
$query = "UPDATE tinyblog SET views = views + 1 WHERE id = :views_id";
$stmt = $db->prepare($query);
$stmt->execute(array(":views_id"=>$article_id));
// End update views
// $retval = mysql_query( $sql, $con );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
$retval->setFetchMode(PDO::FETCH_ASSOC);
while($row = $retval->fetch()) {
?>
<div class="article-blog-indiv">
<?php
echo '<h1>'. $row['blog_title'] .'</h1>';
echo '<p>'. $row['blog_body'] .'</p>';
echo '<p class="views"> Views received: <span id="no_of_views" data-article-views='. $row['views'] .'>'. $row['views'] .'</span></p>';
?>
</div>
<?php
}
?>
<?php include('footer.php'); ?>
Now i need to implement this in bolt

Thanks.