-2
我试图使用Zend将数据从数据源插入到数据库中,并且还在表格中添加了一个列date_updated,以便每当feed中的文章更新时该列也会更新。但问题是,第一篇文章是先插入然后再插入其他文章。所以,当我试图根据date_updated DESC做出前10篇文章的选择时,最后插入的文章会变得更加顶尖,如果我使用ASC,那么较旧的文章将被选中。请建议我如何继续。我写的查询是:数据没有按照正确的顺序从表格使用php
$sql = "INSERT INTO news_article
(original_article_id, headline,summary, keywords, link, section, topic, date_published, date_updated, content, source_id)
VALUES (?,?,?,?,?,?,?,?,?,?,?)
ON DUPLICATE KEY UPDATE
original_article_id = ?,
headline = ?,
summary = ?,
keywords = ?,
link = ?,
section = ?,
topic = ?,
date_published = ?,
date_updated = ?,
content = ?,
source_id = ?";
$values = array(
"original_article_id"=>$id,
"headline"=>$item->title,
"summary"=>$summary,
"keywords"=>$keywords,
"link"=>$item->link,
"section"=>"property",
"topic"=>"property",
"date_published"=>$formattedPubDate,
"date_updated"=>$currentDate,
"content"=>$data,
"source_id"=>"3"
);
$result = $db->query(
$sql,
array_merge(array_values($values), array_values($values))
);
和thenafter我使用下面的查询
SELECT * FROM news_article ORDER BY date_updated DESC LIMIT 0,10
SELECT * FROM news_article ORDER BY date_updated DESC LIMIT 10
那么什么样的数据类型是'date_updated'? INSERT/UPDATE的问题是没有设置正确的日期,还是使用SELECT?缩小你的问题 –
数据类型是你的日期字段?你在输入什么数据?为此,您需要使用“DATE”或“DATETIME”字段。 – 2013-09-24 10:17:55
该数据类型是DATETIME fot date_updated。问题在于,在插入表格中时,饲料顶部的物品比迟到的物品要早。所以,当我做一个选择,这篇文章是在lastis第一次应该不会发生 – user2810532