麻烦与facebook的采伐量的脚本喜欢使用MySQL + PHP [英] Trouble with a script for logging amount of facebook likes with mysql + php

查看:109
本文介绍了麻烦与facebook的采伐量的脚本喜欢使用MySQL + PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个脚本,将记录有多少喜欢(脸谱)的网页已经在MySQL使用Facebook的API,AJAX和MySQL。但此刻它不工作。所有的变量定义,它连接到MySQL和jQuery的嵌入,我没有得到和SQL或PHP错误。任何人都可以看到我要去哪里错了?

来源$ C ​​$ C: 的index.php:

 < PHP
$ SQL =请求mysql_query(SELECT * FROM喜欢ORDER BY ID DESC LIMIT 9);
而($行= mysql_fetch_array($ SQL))
{
?>
< D​​IV ID =FB-根>< / DIV>
&所述;脚本的src =htt​​p://connect.facebook.net/en_US/all.js>&所述; /脚本>

<脚本>
FB.init({

    状态:真正的,
    饼干:真正的,
    XFBML:真
});

FB.Event.subscribe('edge.create',函数(响应){
    警报(响应);

    如果(响应==htt​​p://fbquote.me/like.php?id=<?php打印$行['身份证'];?&gt;中){
$阿贾克斯({
键入:POST,
网址:流行/ ajax_pop.php
数据:ID =&LT; PHP打印$行['身份证'];&gt;有
缓存:假的,
});

    }
});

&LT; / SCRIPT&GT;
                    &LT; BR /&GT; &LT;表格样式=宽度:90%;高度:4PX;类=style11115ALIGN =中心&GT;
    &其中; TR&GT;
        &LT; TD风格=宽度:68px;高度:23px;类=style11111VALIGN =顶&GT;&LT; D​​IV ID =FB-根&GT;&LT; / DIV&GT;&LT;脚本SRC =htt​​p://connect.facebook.net/en_US/all.js #XFBML = 1&GT;&LT; / SCRIPT&GT;&LT; FB:像HREF =http://fbquote.me/like.php?id=<?php打印$行['身份证'];&GT;? 发送=假布局=button_countshow_faces =真字型=&GT;&LT; / FB:等&gt;&LT; / TD&GT;
        &LT; TD风格=HEIGHT:23px级=style11113VALIGN =顶&GT;&LT; A HREF =htt​​p://www.fbquotes.me/like.php?id=<?php打印$行['身份证'];?&gt;中类=style11112&GT;&LT; PHP打印$行['像']; ?&GT;&所述; / a取代;&所述; / TD&GT;
    &LT; / TR&GT;
    &LT; /表&gt;
&LT; PHP}&GT?;
 

alax_pop.php:

 &LT; PHP
include_once(../脚本/ config.php文件);
$像= mysql_real_escape_string($ _ GET ['身份证']);

$ current_pop =请求mysql_query(选择从弹出喜欢WHERE ID = $像)或死亡:(查询失败mysql_error()。)


$流行= $ current_pop + 1;

$更新=请求mysql_query(。。。UPDATE喜欢的POP设置=$弹​​出WHERE ID =$如)或死亡(查询失败:mysql_error());
;

?&GT;
 

解决方案

嗯,有很多的问题,在code以上:

  1. 您的逻辑是完全的错误你在哪里的一切,包括在循环中!

    1. 您是包括次相同的divID多(根据你的MySQL查询9次)
    2. 在包括次FB JS库中的多个(同样的事,JS初始化代码段)
    3. 您缺少APP ID参数
    4. 您正在建设9个表(我不知道这是否意呢!)
    5. 您再一次包括FB codeA表中的几次!
  2. 检查@zzarbi回答您的AJAX的后台页面!

现在解决您的code问题?

  1. 请更多的精力放在学习PHP,HTML和JavaScript的基础知识。
  2. 将您的Facebook和表code外循环。

这样的事情将让你开始:

 &LT; D​​IV ID =FB-根&GT;&LT; / DIV&GT;
&所述;脚本的src =htt​​p://connect.facebook.net/en_US/all.js&GT;&所述; /脚本&GT;
&LT;脚本&GT;
FB.init({
    状态:真正的,
    饼干:真正的,
    XFBML:真
});

FB.Event.subscribe('edge.create',函数(响应){
    $阿贾克斯({
        键入:POST,
        网址:流行/ ajax_pop.php
        数据:URL =+响应
        缓存:假的
    });
});

&LT; / SCRIPT&GT;
&LT; PHP
$结果= mysql_query(SELECT * FROM喜欢ORDER BY ID DESC LIMIT 9);
如果($结果){
?&GT;
&LT;表格样式=宽度:90%;高度:4PX;类=style11115ALIGN =中心&GT;
&LT;?PHP而($行= mysql_fetch_array($结果)){&GT;
    &其中; TR&GT;
        &LT; TD风格=宽度:68px;高度:23px;类=style11111VALIGN =顶&GT;
            &LT; FB:像HREF =?http://fbquote.me/like.php?id=<?php打印$行['身份证'];&gt;中发送=假布局=button_countshow_faces =真字型=&GT;&LT; / FB:等&gt;
        &LT; / TD&GT;
        &LT; TD风格=HEIGHT:23px级=style11113VALIGN =顶&GT;
            &LT; A HREF =htt​​p://www.fbquotes.me/like.php?id=<?php打印$行['身份证'];?&gt;中类=style11112&GT;&LT; PHP打印$行['像']; ?&GT;&所述; / a取代;
        &LT; / TD&GT;
    &LT; / TR&GT;
&LT; PHP}&GT?;
&LT; /表&gt;
&LT; PHP}&GT?;
 

在你的AJAX的网址,读取URL并从中提取的ID。

I am trying to write a script that will log how many likes(Facebook) a page has in Mysql using the Facebook api, ajax and mysql. But at the moment it isn't working. All variables are defined, it is connected to Mysql, and jQuery is embedded and i'm not getting and SQL or PHP errors. Can anyone see where i'm going wrong?

Source code: index.php:

<?php
$sql=mysql_query("select * from likes ORDER BY 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 FROM likes WHERE id=$like") or die ("Query failed: " . mysql_error());


$pop = $current_pop + 1;  

$update = mysql_query("UPDATE like SET pop = ".$pop." WHERE id = ".$like."") or die ("Query failed: " . mysql_error());
;

?>

解决方案

Well, there are lots of issues in the code above:

  1. Your logic is totally wrong where you are including EVERYTHING inside the loop!

    1. You are including the same div "id" multiple of times (9 times according to your Mysql query)
    2. Including the FB JS library multiple of times (same thing for the JS initializing snippet)
    3. You are missing the APP ID parameter
    4. You are building 9 tables (I'm not sure if this is intended too!)
    5. You are once again including the FB code a couple of times in the table!

  2. Check @zzarbi answer for your ajax backend page!

Now a solution to your code issues?

  1. Do more effort on learning the basics of PHP, HTML and Javascript.
  2. Move your Facebook and table code outside the loop.

Something like this will get you 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 * from likes ORDER BY 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 your ajax url, read the url and extract the ID from it.

这篇关于麻烦与facebook的采伐量的脚本喜欢使用MySQL + PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆