Page 1 of 1

How to add no of views in bolt ??

Posted: Wed Nov 09, 2016 2:29 pm
by gautamz07
Hey guys i would like to have a No. of views on each article , i came across the following script on SO:

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 .

Re: How to add no of views in bolt ??

Posted: Wed Nov 09, 2016 2:54 pm
by Celauran
What have you tried so far? Where are you running into trouble?

Re: How to add no of views in bolt ??

Posted: Tue Nov 15, 2016 4:07 pm
by gautamz07
@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)


The code in the article_blog.php where the views get counted looks like following:

Code: Select all

<?php   include('header.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);
   // End update views

      // $retval = mysql_query( $sql, $con );
      if(! $retval ) {
         die('Could not get data: ' . mysql_error());

   while($row = $retval->fetch()) {

   <div class="article-blog-indiv">
	      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>';
<?php   include('footer.php');  ?>

Now i need to implement this in bolt :)