2

FacebookのイベントIDを取得したテーブルがあります。

id    event_id    attendings
 1    12345678

event_id を取得してクエリに入れます。

$query = 'https://graph.facebook.com/fql?q=SELECT+attending_count+FROM+event+WHERE+eid='.$event_id.'&access_token='.$params1['access_token'];
$result = file_get_contents($query);
$obj = json_decode($result, true);
foreach ($obj['data'] as $item) { 
$attend = $item['attending_count'];
} 

ここで、event_id = 12345678 のテーブル出席を $attend で更新します

問題は、テーブルにあるすべての行でどうすればよいかです

ありがとう

私のつづりで申し訳ありませんが、私の母のトンクではなく英語です。

4

2 に答える 2

1

イベントごとに facebook API 呼び出しを行う必要があるため、これをすべて大きなループで行う必要があるようです。

したがって、最初のステップは、使用することを選択した MySQL ライブラリを使用して、テーブルからすべての結果を取得することです。クエリは次のようになります。

SELECT id, event_id FROM table;

結果セットをループするときに、次のようにデータを配列に割り当てたとします。

$array[$row['id']] = $row['event_id'];

ここで、次のようにその配列をループします。

foreach($array as $db_id => $event_id) {
    // your facebook code here

    // update the database with your library of choice using this query
    UPDATE table SET attendings = $attending WHERE id = $db_id
}
于 2012-12-28T23:46:17.543 に答える
1

単一の FQL クエリで目的の値をすべてフェッチattending_countし、結果に対するループ内から既存のテーブルを更新できます。

define('FB_FQL_API', 'https://graph.facebook.com/fql?');

$dbh = new PDO("mysql:dbname=$dbname", $username, $password);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$qry = $dbh->query('
  SELECT GROUP_CONCAT(event_id)
  FROM   my_table
');

$upd = $dbh->prepare('
  UPDATE my_table
  SET    attendings = :attend
  WHERE  event_id   = :event
');

$fql = '
  SELECT eid, attending_count
  FROM   event
  WHERE  eid IN ('.$qry->fetchColumn().')
';

$url = FB_FQL_API . http_build_query([
  'q'            => trim(preg_replace('/\s+/', ' ', $fql)),
  'access_token' => $params1['access_token']
]);

$res = json_decode(file_get_contents($url));

foreach ($res->data as $event) $upd->execute([
  ':attend' => $event->attending_count,
  ':event'  => $event->eid
]);
于 2012-12-28T23:38:56.953 に答える