jquery - Trouble with a script for logging amount of facebook likes with mysql + php -


i trying write script log how many likes(facebook) page has in mysql using facebook api, ajax , mysql. @ moment isn't working. variables defined, connected mysql, , jquery embedded , i'm not getting , sql or php errors. can see i'm going wrong?

source code: index.php:

<?php $sql=mysql_query("select * likes order id desc limit 9"); while($row=mysql_fetch_array($sql)) { ?> <div id="fb-root"></div> <script src="http://connect.facebook.net/en_us/all.js"></script>  <script > fb.init({      status: true,     cookie: true,     xfbml: true });  fb.event.subscribe('edge.create', function(response) {     alert(response);      if (response == "http://fbquote.me/like.php?id=<?php print $row['id']; ?>") { $.ajax({ type: "post", url: "popular/ajax_pop.php", data: "id=<?php print $row['id']; ?>"  cache: false, });      } });  </script>                     <br />  <table style="width: 90%; height: 4px;" class="style11115" align="center">     <tr>         <td style="width: 68px; height: 23px;" class="style11111 " valign="top"><div id="fb-root"></div><script src="http://connect.facebook.net/en_us/all.js#xfbml=1"></script><fb:like href="http://fbquote.me/like.php?id=<?php print $row['id']; ?>" send="false" layout="button_count" show_faces="true" font=""></fb:like></td>         <td style="height: 23px" class="style11113" valign="top"><a href="http://www.fbquotes.me/like.php?id=<?php print $row['id']; ?>" class="style11112"><?php print $row['like']; ?></a></td>     </tr>     </table> <?php } ?> 

alax_pop.php:

<?php include_once("../scripts/config.php"); $like = mysql_real_escape_string($get_['id']);  $current_pop = mysql_query("select pop likes id=$like") or die ("query failed: " . mysql_error());   $pop = $current_pop + 1;    $update = mysql_query("update set pop = ".$pop." id = ".$like."") or die ("query failed: " . mysql_error()); ;  ?> 

well, there lots of issues in code above:

  1. your logic totally wrong including inside loop!

    1. you including same div "id" multiple of times (9 times according mysql query)
    2. including fb js library multiple of times (same thing js initializing snippet)
    3. you missing app id parameter
    4. you building 9 tables (i'm not sure if intended too!)
    5. you once again including fb code couple of times in table!
  2. check @zzarbi answer ajax backend page!

now solution code issues?

  1. do more effort on learning basics of php, html , javascript.
  2. move facebook , table code outside loop.

something started:

<div id="fb-root"></div> <script src="http://connect.facebook.net/en_us/all.js"></script> <script > fb.init({     status: true,     cookie: true,     xfbml: true });  fb.event.subscribe('edge.create', function(response) {     $.ajax({         type: "post",         url: "popular/ajax_pop.php",         data: "url=" + response          cache: false     }); });  </script> <?php $result=mysql_query("select * likes order id desc limit 9"); if($result) { ?> <table style="width: 90%; height: 4px;" class="style11115" align="center"> <?php while($row=mysql_fetch_array($result)) { ?>     <tr>         <td style="width: 68px; height: 23px;" class="style11111 " valign="top">             <fb:like href="http://fbquote.me/like.php?id=<?php print $row['id']; ?>" send="false" layout="button_count" show_faces="true" font=""></fb:like>         </td>         <td style="height: 23px" class="style11113" valign="top">             <a href="http://www.fbquotes.me/like.php?id=<?php print $row['id']; ?>" class="style11112"><?php print $row['like']; ?></a>         </td>     </tr> <?php } ?> </table> <?php } ?> 

in ajax url, read url , extract id it.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -