在这段代码中,有两个foreach。当我单独使用它时,它工作得很好。然而,它不能一起工作。这个问题我已经纠结了两天了。
$urls = nl2br($this->input->post('urls'));
$result = explode("<br />", $urls);
$n = 0;
foreach($result as $row)
{
$n++;
$Google_Play_URL = $row;
$string = file_get_contents($Google_Play_URL);
$dom = new DOMDocument();
@$dom->loadHTML($string);
$anchors = $dom->getElementsByTagName('a');
$i = 0;
foreach ($anchors as $anchor)
{
$i++;
if ($anchor->nodeValue === 'Email Developer') {
$email = str_replace('mailto:', '', $anchor->getAttribute('href'));
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo $email;
$id = $this->session->userdata(SESSION_USERID);
$country = 'US';
$type = 'android';
$query = 'SELECT idx FROM db_advertisers WHERE email = "'.$email.'"';
$result = $this->db->query($query);
if($result->num_rows() < 1)
{
$query = 'INSERT INTO db_advertisers (email, type, url, country, submit_user) VALUES ("'.$email.'", "'.$type.'", "'.$Google_Play_URL.'", "'.$country.'", "'.$id.'")';
$this->db->query($query);
}
}
}
}}
当我发送多个值时,此代码仅保存一个数据。它假定要保存多个数据。你能看到问题所在吗?
发布于 2013-01-04 15:46:50
唯一明显的问题是,在内部foreach循环中,您设置了
$result = $this->db->query($query);这个变量与外部foreach循环中的变量相同
foreach($result as $row)更改其中一个变量名称可以解决此问题。
https://stackoverflow.com/questions/14153145
复制相似问题