开发者

Isn't got anyway to insert by descending? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussio开发者_高级运维n. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

What I need to insert is by descending record.

my code:

mysql_query("INSERT INTO entertainment VALUES ('','$result','$date')");

result:

id  result  date
1   a       26/9/2011
2   b       25/9/2011 
3   c       24/9/2011

What I want is:

id  result  date
1   c       24/9/2011
2   b       25/9/2011 
3   a       26/9/2011

Isn't possible do it ?

here is my full code, what i doing now i rss grabbing,once i grab all the result i will insert the result to my database:

     $content = file_get_contents($feed_url);
        $xml = new SimpleXmlElement($content);          
            foreach($xml->channel->item as $entry){ 

                $title = mysql_real_escape_string(strip_tags($entry->title));
                $description = mysql_real_escape_string(strip_tags($entry->description));   
                mysql_query("INSERT INTO entertainment VALUES ('','$entry->pubDate','$title','$description')"); 
                }


No.

This is a really bad idea. The (autoincrement) ID column should not be significant for your data - so you really shouldn't care about its value.

Furthermore, how would MySQL know where to start from? If you insert three, it should start from 3 and count to 1, but what if you insert more later?

Instead of changing the order while inserting, you should probably change the query that reads the data later. Have that query return the data really the way you want it.

SELECT *
FROM entertainment
ORDER BY result DESC


INSERT INTO orders (id result date) select id result date from tablename order by id desc


Yes, insert the data in any way, and use SELECT * FROM entertainment ORDER BY date Desc at the time of retrieval.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜