0

こんにちは、foreachループの値を使用してSQLデータベースの列を更新しようとしていますが、foreach()に無効な引数が指定されています

        foreach($ids as $id){
    $ch = curl_init();

    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, "http://api.twitter.com/1/
    users/lookup.json?user_id=".$id."");
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // grab URL and pass it to the browser
    $contents = curl_exec ($ch);
    $ok=array();
    $ok=json_decode($contents,true);
    foreach($ok['results'] as $p){
        $location=$p['location'];
        $query=mysql_query("UPDATE tweets SET location=".$location."
         WHERE from_user_id=".$id."");
        if($query){
            print'ok';
        }else{print'sds';}
    }
    // close cURL resource, and free up system resources
    curl_close($ch);
    }

私は何が間違っているのですか?

人々を応援します!!!!

4

2 に答える 2

1

必要なのはこれだけです。最後のツイートを引っ張るだけですが、良いスタートです。twitter api への呼び出しが機能しなくなりました。ブラウザー ウィンドウに配置すると、エラーが発生することがわかります。

$contents = file_get_contents("http://api.twitter.com/users/".$id.".json");
$ok=json_decode($contents,true);

# For Testing Purposes
#echo '<pre>';
#var_dump($ok);
#echo '</pre>';

echo $ok['location'];
于 2012-07-29T15:48:28.547 に答える
0

PHP 配列は、連想かどうかに関係なく、ペアごとにキーと値を持ちます。

したがって、配列foreach($ids as $id_number => $id) {に関する詳細情報を提供しなかったため、推測どおりになるはずです。$ids

于 2012-07-29T14:54:15.057 に答える