简体   繁体   中英

How to create PHP Array from Mysql

I am trying to create an array from a MySQL query that I have.
This is to update facebook status' with the access tokens I have stored in my MySQL database.
I am able to pull the access tokens without problem, but am having trouble creating an array that will list them as follows:
array('token1', 'token2'..etc)
I have formatted the array to implode and give '' and a , but it still will not work.
any suggestions would be greatly appreciated.

$results = mysql_query("SELECT access_token 
                        FROM demographic 
                        ORDER BY access_token ASC");
while($access_token_array = mysql_fetch_assoc($results)) {
  $list_access_token[] = $access_token_array['access_token']; 
}

$comma_separated_quote = ("'" . implode("', '", $list_access_token) . "'");
$arr = array ($comma_separated_quote);  

foreach ($arr as $tokens) {
  $facebook->api('/me/feed','POST',array('access_token' => $str,'message' => 'test'));
}

Maybe I am reading this wrong but it looks like you want this...

<?php
$results = mysql_query("SELECT access_token FROM demographic ORDER BY access_token ASC");
while($access_token_array = mysql_fetch_assoc($results)) {
    $facebook->api('/me/feed', 'POST', array('access_token' => $access_token_array['access_token'], 'message' => 'test'));

}
?>

Are you trying to post a message for every access_token?

尝试用$ tokens替换$ str ,它应该可以工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM