PHP Developers Network
http://forums.devnetwork.net/

How to add no of views in bolt ??
http://forums.devnetwork.net/viewtopic.php?f=72&t=143126
Page 1 of 1

Author:  gautamz07 [ Wed Nov 09, 2016 3:29 pm ]
Post subject:  How to add no of views in bolt ??

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 .

Author:  Celauran [ Wed Nov 09, 2016 3:54 pm ]
Post subject:  Re: How to add no of views in bolt ??

What have you tried so far? Where are you running into trouble?

Author:  gautamz07 [ Tue Nov 15, 2016 5:07 pm ]
Post subject:  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

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

Syntax: [ Download ] [ Hide ]
<?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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/