2012-04-25 13 views
1

以下のスクリプトは、ウェブサイト上のいくつかの項目をエコーし​​て、さまざまなrssフィードをmysqlデータベースに挿入するのにかなりうまく機能します。しかし、私が 'mysql_query'を注文して制限しようとすると、動作が停止します。 ORDER BYとLIMITが間違った位置に置かれている可能性がありますが、私が見る唯一の可能性はそれらをmysql_queryに配置することです。誰でも知っている?mysql_queryによる制限と順序

$feeds = array('https://www.ictu.nl/rss.xml', 'http://www.vng.nl/smartsite.dws?id=97817'); 
foreach($feeds as $feed) { 
    $xml = simplexml_load_file($feed); 

    foreach($xml->channel->item as $item) 
    { 
    $date_format = "j-n-Y"; // 7-7-2008 
      echo date($date_format,strtotime($item->pubDate)); 
      echo ' '; 
      echo ' '; 
      echo '<a href="'.$item->link.'" target="_blank">'.$item->title.'</a>'; 
      echo '<div>' . $item->description . '<br><br></div>'; 

    mysql_query("INSERT INTO rss_feeds (id, title, description, link, pubdate) 
       VALUES (
     '', 
     '".mysql_real_escape_string($item->title)."', 
     '".mysql_real_escape_string($item->description=htmlspecialchars(trim($item->description)))."', 
     '".mysql_real_escape_string($item->link)."', 
     '".mysql_real_escape_string($item->pubdate)."')")ORDER BY 'title' LIMIT 0,10;  
    } 
} 

答えて

4

ORDER BYおよびLIMITは、INSERT文では使用されません。これらはSELECT文で使用する必要があります。

+0

ありがとう、本当にありがとうございます。同じmysql_query行内のINSERT文の次にSELECT文を使用できるかどうか知っていますか? – smd

+0

1つのページで複数のクエリを実行できます。ただし、各ステートメントを個別に照会する必要があります。 INSERTの前にSELECT文を実行したい場合は、$ selres = mysql_query($ selsql)のような別の呼び出しを行う必要があります。次に、insertには$ insres = mysql_query($ inssql)のようなものがあります。 – Shane

+0

下記の(回答)フィールドで何が起きているかをご覧ください。 – smd

0

mysql_queryと表記についてはわかりません。まだ間違っています。

$selSQL = SELECT * FROM rss-feeds ORDER BY 'title';  
$insSQL = "INSERT INTO 'rss_feeds' (id, title, description, link, pubdate) 
        VALUES (
      '', 
      '".mysql_real_escape_string($item->title)."', 
      '".mysql_real_escape_string($item->description=htmlspecialchars(trim($item->description)))."', 
      '".mysql_real_escape_string($item->link)."', 
      '".mysql_real_escape_string($item->pubdate)."'); 

$selres = mysql_query($selsql); 
$insRes = mysql_query($insSQL); 
0

カラム名を囲むために `。 'を使用すると、カラム名の前後に一重引用符を使用しないでください。また、あなたの$ selSQLの周りに引用符はありませんでした。下記を参照して試してみてください。

$selSQL = "SELECT * FROM `rss-feeds` ORDER BY `title`";  
$insSQL = "INSERT INTO `rss_feeds` (`id`, `title`, `description`, `link`, `pubdate`) 
      VALUES (
      '', 
      '".mysql_real_escape_string($item->title)."', 
      '".mysql_real_escape_string($item->description=htmlspecialchars(trim($item->description)))."', 
      '".mysql_real_escape_string($item->link)."', 
      '".mysql_real_escape_string($item->pubdate)."')"; 

$selres = mysql_query($selsql); 
$insRes = mysql_query($insSQL); 
関連する問題