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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大