views:

98

answers:

2

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>"; 
A: 

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.

vjo
Thank you! It works now :]
Izumi
A: 

I know what I'm doing x'D And I know that it is wrong, but I really have no idea how to correct it -quite the beginner at php/mysql- How can I do what you just said?

Izumi