How to store Facebook shares in database using JSON?

7 replies
I want to store Facebook shares of my website in the MySQL database. I used following code to get the share value when page load. But I don't know how to save it into database?
Code:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script> 
        $x='http://api.facebook.com/method/links.getStats?urls=http://www.yahoo.com&format=json'; 
$.ajax({   
       url: 'http://api.facebook.com/method/links.getStats?urls=http://www.yahoo.com&format=json',  
      success: function(data){     
      $("#dd").html(data[0]['comment_count']);   
} });
</script>
In the body section I use div to show this value

HTML Code:
Comment count = <div id="dd"></div>
#database #facebook #json #shares #store
  • Profile picture of the author geekSoftware
    I'm not sure why, but I'm not able to post my code here, so full post I've written here you will find on: http://pastebin.com/pidKQ66p
    {{ DiscussionBoard.errors[9837751].message }}
    • Profile picture of the author mikea12
      Geeksoftware is right, your javascript is fine but the main thing is to have a script to handle the sql insert.

      If you plan on working with a lot of data I would suggest building a controller, or using a PHP framework like laravel.
      {{ DiscussionBoard.errors[9838227].message }}
    • Profile picture of the author Ramesh8248
      Originally Posted by geekSoftware View Post

      I'm not sure why, but I'm not able to post my code here, so full post I've written here you will find on: [HTML] You can change this: [HTML] <script type="text/javascript"> $.ajax({ - Pastebin.com
      Thank you for your help geekSoftware but I still cant store the values in my database. I check database connection and its working, but I still cant store the values...
      {{ DiscussionBoard.errors[9842434].message }}
      • Profile picture of the author geekSoftware
        Originally Posted by Ramesh8248 View Post

        Thank you for your help geekSoftware but I still cant store the values in my database. I check database connection and its working, but I still cant store the values...
        Please give me more information, like do you using MySQL or MySQLi, what is the name of your database/table where you want to store that information, what is the table structure etc. Without that I can't write you 100% correct code.
        {{ DiscussionBoard.errors[9842497].message }}
        • Profile picture of the author Ramesh8248
          Originally Posted by geekSoftware View Post

          Please give me more information, like do you using MySQL or MySQLi, what is the name of your database/table where you want to store that information, what is the table structure etc. Without that I can't write you 100% correct code.
          I am trying to run this script on my PC using WAMP.
          I am using MySQL
          Database name: share
          table name: sharetb
          column 1: id
          column 2:stats
          {{ DiscussionBoard.errors[9851818].message }}
  • Profile picture of the author Ramesh8248
    It was my mistake...
    Its working great...
    Thank you geeksoftware
    {{ DiscussionBoard.errors[9853576].message }}
    • Profile picture of the author geekSoftware
      Originally Posted by Ramesh8248 View Post

      It was my mistake...
      Its working great...
      Thank you geeksoftware
      It's my pleasure if it's working for you.
      {{ DiscussionBoard.errors[9853616].message }}

Trending Topics