2
我試圖用xpath刪除一些數據,然後插入到SQL中。將循環數據插入到sql中
回聲工作正常,但插入到SQL時,它只獲取第一行。
例子:
<?php
$res=mysql_query("SELECT table.title, table.link FROM table WHERE table.link LIKE 'http://www.%' AND streams.title = ''");
while($row=mysql_fetch_array($res))
{
$html = new DOMDocument();
@$html->loadHtmlFile($row["link"]);
$xpath = new DOMXPath($html);
foreach ($xpath->query("//table[@style='margin-left: 5px;']//td[@width='150']//a") as $files)
{
$html = new DOMDocument();
@$html->loadHtmlFile($files->getAttribute('href'));
$xpath = new DOMXPath($html);
$hl = $xpath->query("//div[@style='width:742px']/a[preceding-sibling::div[@id='help1']]/@href")->item(0)->nodeValue;
$link=serialize(array('link' => $hl));
$link=sqlesc($link);
echo $link; // all lines gets printed, thats okay?
mysql_query("UPDATE streams SET streams.hl=$link") or die(mysql_error()); // Only first line gets inserted, why?
}
}
?>
您的UPDATE statment沒有WHERE clausule
,這聽起來像一個問題... –
我也試過與WHERE clausule,仍然有問題。 – user1846022