Jump to content

order by most recent date


astralaaron

Recommended Posts

how do I order messages by the most recent date they were posted?I am making a little blog system, on the front page it is basically a table that displays the users that have blogs, and I want to display the date of the most recent post they have made and they should be orderd with the most recent poster on top..any advice?

Link to comment
Share on other sites

You can order stuff in your query by column name.

GET * FROM blog ORDER BY date LIMIT 10

Limit ten is for when you want to limit the results to the ten newest posts, in this case.Hope this helps.

Link to comment
Share on other sites

Sure... :); forgot to check the syntax. Day off... brain...melting...Don't forget to replace 'date' with the actual name of the data you want to sort by.

Link to comment
Share on other sites

ran into a problem, it does order by the most recent date / time. but it thinks 5:50 AM is more recent than right now, 1:55 PMmy date / time looks like this 18/05/07 05:55:19 (which was AM) and 18/05/07 01:55:30 (which is PM)the 5:55 date gets listed before 1:55.. does anyone get whats going wrong here?how can I get if it is am or PM so i can really order by the most recent date?

Link to comment
Share on other sites

If you have the primary key field set to auto increment, just order by primary key

SELECT * FROM table_name ORDER BY primary_key_field DESC

and it will order them correctly.Remember, only if primary key field is auto increment.

Link to comment
Share on other sites

ran into a problem, it does order by the most recent date / time. but it thinks 5:50 AM is more recent than right now, 1:55 PMmy date / time looks like this 18/05/07 05:55:19 (which was AM) and 18/05/07 01:55:30 (which is PM)the 5:55 date gets listed before 1:55.. does anyone get whats going wrong here?how can I get if it is am or PM so i can really order by the most recent date?
That could be because 5 > 1, add 12 to the time when it is PM so 1 becomes 13 which is > 5.
Link to comment
Share on other sites

That could be because 5 > 1, add 12 to the time when it is PM so 1 becomes 13 which is > 5.
yes I understand why it is doing that lol.. there is no determining what is am and what is PM. how do you do that time, 1:00 pm = 13:00 ?
Link to comment
Share on other sites

this is where the date comes from, please help me fix that if you can so it knows the difference between AM and PM when I order them! thanks :-)

<?phpinclude('blogcheck.php');$blog_user = $_GET['user'];mysql_connect("localhost","root","******")or die("could not connect");mysql_select_db("t_blogs")or die("could not select db");$topic = $_POST['topic'];$detail = $_POST['body'];$date = date("d/m/y h:i:s");$sql = mysql_query("INSERT INTO {$blog_user}_topic (topic, detail, date) VALUES ('$topic', '$detail', '$date')");if (!$sql) {die('error: ' . mysql_error());} else {	$sql2 = mysql_query("UPDATE bloggers SET post_date = '$date' WHERE name = '$blog_user'");	if (!$sql2) {	die('error: ' . mysql_error());	}}header("location:http://localhost/tuneinordie/blog/panel.php?user=$blog_user");?>

Link to comment
Share on other sites

works perfect, thanks.
this worked perfect I thought, untill it turned AM again.. it is the same problem but backwards!1 am = 13:001 pm will be 13:00 also...there has to be a way to do this.. anyone know?it should go 1:00 for am - 24:00 (13:00 for 1 pm)
Link to comment
Share on other sites

this worked perfect I thought, untill it turned AM again.. it is the same problem but backwards!1 am = 13:001 pm will be 13:00 also...there has to be a way to do this.. anyone know?it should go 1:00 for am - 24:00 (13:00 for 1 pm)
My bad, you might want to add a conditional in there. :) $date=date('d/m/y ');$h=date('h');if (date("A")=="PM") { $h+=12;}$date.=$h.date(':i:s');
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...