PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue May 23, 2017 5:36 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Nov 09, 2016 3:29 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 317
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 .


Top
 Profile  
 
PostPosted: Wed Nov 09, 2016 3:54 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6243
Location: Montreal, Canada
What have you tried so far? Where are you running into trouble?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 5:07 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 317
@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:

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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group