开发者

sorting the topic's by descending ( new topics and replayed topics )

i am building a topic's system i use this mysql

CREATE TABLE `ftopics` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `catid` int(11) NOT NULL,
  `userid` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `full` text NOT NULL,
  `date` varchar(100) NOT NULL,
  `hits` varchar(100) NOT NULL,
  `tag开发者_运维知识库s` varchar(255) NOT NULL,
  `lastrep` varchar(100) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM;

the column ( lastrep ) it updated when the member add a new replay for the topic

$time=time();
$result = mysql_query("UPDATE ftopics SET lastrep='$time' WHERE id='$tid'") 
or die(mysql_error());  

ok now when i want to output the threads and i want to order the topics's by ( id descending ) and also by ( lastrep descending ) in the same time.

explain>>>>

when i user post a new topic it shows in the first row in the output but when a nother user post a replay in another topic it should be shows the first one in the table output.

i used this query to output

$get_topics  = mysql_query("select id,catid,userid,name,date,lastrep from ftopics where catid='$catid' ORDER BY lastrep DESC, id DESC") or die(mysql_error());

i got the new topic in the first row but any replayed topic it still now going into the top.

i hope that i explained my Q in good way.

regards Piny


It sounds like you want to have two columns in your table, one for time created and one for time modified. The 'modified' column would be the one you update when a new reply is added, but you could use the 'created' column to order by so your table is always ordered by the creation date.

Sorry if I've misunderstood.

EDIT And you should definitely make those columns int/datetime as suggested above so the ordering is performed as you expect.


MySQL has a dateTime data type, use it for both date and lastRep columns. Then correct your insert and update queries to input proper dateTimes. This will probably correct the sorting issue, it is at least the first thing you should try.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜