duandi8544 2010-01-05 16:07
浏览 26
已采纳

PHP / MySQL问题[facebook-related]

Okay... I'm having the following problem - in my facebook application I let people add quotes sending them to my DB with their user_id, post_id and date. Then there's a browse page where people see the posts - so far, so good. But then I add a button that lets my users set the said post as their status. Still all good. However when I hit the button what it does is setting all the posts in the DB as my status, one by one until they all print out as my statuses. I'm sure that it is because of the 'while' function I use and because I am not sure how to print out all posts and being able to add to each the said button, holding only the specific post_id from the db ._.'

So in other words, it is a PHP/MySQL problem mainly, so even if you are not familiar with FBML, you can still help me out with the code...

Think of it as a list of posts and each should have a button doing something and being somehow attached to only the specific post.

The code is the following:

.... some code here ....

$query = 'SELECT * FROM tb_table ORDER BY `time` DESC';
$results = mysql_query($query);

---some other code---

while($line = mysql_fetch_assoc($results)) {
echo '<TABLE BORDER=0><TR VALIGN=TOP><TD>'; 
echo "<fb:profile-pic uid=".$line['userid']." size='square' facebook-logo='true'></fb:profile-pic></TD>";
echo "<TD>".$line['postid']."<br>"."<br>"."Posted by: ".$data['first_name'].$data['last_name']."<br>".date("F j, Y, g:i a", $line['fb_time'])."</TD>";
//Problems start from here
echo $facebook->api_client->users_setStatus($line['postid']) ; 

echo '<div id="statusdiv" style="display:<?=$visibility;?>;">   
    <form method="POST">   
           <input type="submit" value="change status" />   
    </form>   
</div>  ';
echo "</TR></TABLE><br>"; 
  • 写回答

1条回答 默认 最新

  • doukong1901 2010-01-05 16:15
    关注

    The thing you're doing now is every time you loop through your mysql resultset you call the users_setStatus function which then sets your status (for every iteration).

    You want to add a hidden input field to the form which contains the $line['postid'] and then call users_setStatus after a POST of the form. In that way you only change your status once.

    Update

    Remove the call to users_setStatus from the while loop. Change your form like this:

    echo '<div id="statusdiv" style="display:<?=$visibility;?>;">   
        <form method="POST">   
               <input type="submit" value="change status" />
               <input type="hidden" name="line" value="'.$line['postid]'.'" />   
        </form>   
    </div>  ';
    

    Then, catch the POST variable upon submitting. With something like:

    if (isset($_POST['line'])) {
    echo $facebook->api_client->users_setStatus($_POST['line']) ;
    }
    

    See http://www.w3schools.com/php/php_forms.asp for more info.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题