foreach php循环中的多个请求

时间:2013-09-04 15:12:02

标签: php ajax request

我想获取用户列表的推文并将其保存到数据库中。这些推文是在名为tweets.php的文件中生成的,该文件连接到twitter api。如果我只有一个名字,我可以使用file_get_contents获取推文,然后插入它们。但如果我有一组用户,我该怎么做呢?

以下是我想要做的事情的说明。据我所知,不可能使用添加了变量的file_get_contens(如在脚本中),但我应该使用什么instaed。是ajax请求的唯一方法。在这种情况下不太确定如何结合ajax和php,我会坚持留在php中。

$values = array(0 => 'Oscar', 1 => 'Peter', 2 => 'Paul');

 foreach($values as $value) {


 $tweetJson = file_get_contents('http://localhost/news/tweets.php?name='<?php echo .$value.    ?>)');


$tweetJson  = json_decode($tweetJson, true); 


$statement = $dbh->prepare("INSERT INTO tweet (tweet, title) VALUES (?, ?)");

foreach($tweetJson  as $key => $value) {
$statement->execute(array($value['text'], $value['user']['name']));

}


} 

0 个答案:

没有答案