Andy11548 Posted July 11, 2011 Share Posted July 11, 2011 Hello, I've got a query which is: $replyQ = mysql_query("SELECT * FROM `forum_replys` WHERE `sub_cat_id`='".$subsF['id']."' ORDER BY `datetime` DESC"); I want it to show the latest reply, going by the most recent date and time field which looks like: 2011-07-11 10:23:03 However, the query, doesn't work. It doesn't display the lastest one, even if I changed it from 'DESC' to 'ASC', no matter what, it doesn't show the lastest replys. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/ Share on other sites More sharing options...
teynon Posted July 11, 2011 Share Posted July 11, 2011 What type is datetime? Try sorting by a completely different field and see if it orders it at all. Can we see more of your script? Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241163 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 I've got one page working, but I think, I've got another way of odering, what part of the code would you need? seeing as its a query problem. The field type is "datetime". Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241167 Share on other sites More sharing options...
teynon Posted July 11, 2011 Share Posted July 11, 2011 I prefer to see all of the code because a lot of times there are other contributing factors that we are never fully aware of. Just don't include passwords and things like that. Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241170 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 Well, I know its not another problem, because I tried it using "ids" which is what I'm using now, but sure, have fun reading through my messy code, haha . <?php include './includes/header.php'; include './includes/scripts/shoutbox.php'; $catsQ = mysql_query("SELECT * FROM `forum_cats` ORDER BY `id` ASC"); $catsF = mysql_fetch_assoc($catsQ); ?> <div id="forumContainer"> <div id="forumHolder"> <br /> <?php $catsQ = mysql_query("SELECT * FROM `forum_cats`"); $catsF = mysql_fetch_assoc($catsQ); do { echo '<div class="forumCats">'.$catsF['name'].'</div>'; $subsQ = mysql_query("SELECT * FROM `forum_subs` WHERE `cat`='".$catsF['name']."'"); $subsF = mysql_fetch_assoc($subsQ); do { $topicQ = mysql_query("SELECT * FROM `forum_topics` WHERE `sub_cat_id`='".$subsF['id']."'"); $topicF = mysql_fetch_assoc($topicQ); $topicR = mysql_num_rows($topicQ); $replyQ = mysql_query("SELECT * FROM `forum_replys` WHERE `sub_cat_id`='".$subsF['id']."' ORDER BY `id` DESC"); $replyF = mysql_fetch_assoc($replyQ); $replyR = mysql_num_rows($replyQ); echo '<div class="forumSubs"> <div class="subsLeft"><a href="view.php?id='.$subsF['id'].'¤tpage=1">'.$subsF['name'].'</a><br /><span>'.$subsF['description'].'</span></div> <div class="subsRightH"> <div class="subsRLeft">Posts: '.$replyR.'<br />Topics: '.$topicR.'</div> <div class="subsRRight">'; if($replyR > 0) { echo 'Last post by: '.$replyF['username'].'<br />in: '.$replyF['topic_name'].'<br />'; if($replyF['date'] == date('Y-m-d')) { echo '<strong>Today</strong> at '.$replyF['time']; } else { echo 'on '.$replyF['date'].' at '.$replyF['time']; } } else { echo 'No posts'; } echo '</div> </div> <div class="clearfloat"></div> </div> '; } while($subsF = mysql_fetch_assoc($subsQ)); } while($catsF = mysql_fetch_assoc($catsQ)); ?> </div> </div> <?php include './includes/footer.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241171 Share on other sites More sharing options...
LeadingWebDev Posted July 11, 2011 Share Posted July 11, 2011 SELECT *, date_format(datetime, %m/%e/%Y) as datetime FROM `forum_replys` WHERE `sub_cat_id`='".$subsF['id']."' ORDER BY `datetime` DESC not sure, but this should help you Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241174 Share on other sites More sharing options...
teynon Posted July 11, 2011 Share Posted July 11, 2011 What happens if you put LIMIT 1 on that query? Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241178 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 I'll try it on my next page, and let you know, for now, the way I've done it using id's works just fine. Thanks for helping though, Andy. Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241180 Share on other sites More sharing options...
LeadingWebDev Posted July 11, 2011 Share Posted July 11, 2011 Andy, you can try using timestamp Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241209 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 May I ask what the difference between "Timestamp" and "datetime" is? They both show up exactly the same in the database, so what is the actual difference? Thanks, Andy. Quote Link to comment https://forums.phpfreaks.com/topic/241653-ordering-problem/#findComment-1241212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.