Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
foreach php循环中的多个请求_Php_Ajax_Request - Fatal编程技术网

foreach php循环中的多个请求

foreach php循环中的多个请求,php,ajax,request,Php,Ajax,Request,我想获得一个用户列表的tweet,并将其保存到数据库中。tweets在一个名为tweets.php的文件中生成,该文件连接到twitterapi。如果我只有一个名字,我可以使用file_get_内容获取推文,然后插入推文。但是,如果我有一组用户,我该怎么做呢 下面是我想做的一个例子。据我所知,不可能使用添加了变量的file_get_contens(如在脚本中),但我应该使用instaed。是ajax请求的唯一方法。在这种情况下,我不太确定如何将ajax和php结合起来,我希望继续使用php $v

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

下面是我想做的一个例子。据我所知,不可能使用添加了变量的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']));

}


} 
$values=array(0=>'Oscar',1=>'Peter',2=>'Paul');
foreach($value作为$value){
$tweetJson=文件获取内容('http://localhost/news/tweets.php?name=')');
$tweetJson=json_decode($tweetJson,true);
$statement=$dbh->prepare(“插入到tweet(tweet,title)值(?,)”;
foreach($tweetJson作为$key=>$value){
$statement->execute(数组($value['text'],$value['user']['name']);
}
} 

您有语法问题
应该是:
$value.
先清除它。好的,谢谢您指出这一点!但是文件获取内容的方法正确吗?为什么不?如果您的
tweets.php
输出有效且正确的json字符串,这意味着您可以像自己那样将其转换为数组
var\u dump($tweetJson)
文件之后获取内容
并将其添加到问题中。所以人们可以意识到这一点。正如我在问题中所写的,我已经读到,你不应该发送包含文件内容的变量。但也许这是不对的。