Page 2 of 2

Posted: Wed Oct 11, 2006 11:12 am
by Javrixx
Everah wrote:Ok, how are your dates stored in your database?
Copy and paste from the phpAdmin:

Edit Delete Test File Name 2006-10-04 1pa542iqzn92oepaz test 1
Edit Delete Steve's Survey 2005-10-03 1pa542iqzn92oepaz stevesurvey 1
Edit Delete test17 2006-10-04 17iz831nqbe84pqinz test17 17
Edit Delete filename 2006-10-10 encryptedfoldername encryptedfilename 1
Edit Delete filename2 2006-10-10 foldername filename 1
Edit Delete anotherfilename 2006-02-08 folder file 1



So it's 2006-12-25. Year-Month-Day

Posted: Wed Oct 11, 2006 11:19 am
by RobertGonzalez
As per volka's post (notice that the formatted date is aliased to a field named 'datef', so that is what you reference in the while loop, not the field `date`):

Code: Select all

<?php
{
	// list all users
	$sql = "SELECT DATE_FORMAT(`date_field`, '%W %M %Y') as datef, filename, folder, file
		FROM `table_name`
		WHERE `user_id` = $userid
		ORDER BY `date_field` LIMIT $start, $limit";
}

if ($result = mysql_query($sql)) {
	echo $row['datef'] . "<br />\n";
}
?>

Posted: Wed Oct 11, 2006 11:29 am
by volka
and to reverse the order add DESC to the statement.
ORDER BY `date_field` DESC


ORDER BY fieldA ASC (ascending, default)
ORDER BY fieldA DESC (descending)
also works for more than one field: ORDER BY fieldA ASC, fieldB DESC

Posted: Wed Oct 11, 2006 11:33 am
by Javrixx
Awesome, everything works exactly as needed. Thank you so much guys for the help, I really appreciate it. I just have one last thing to figure out until I'm almost finished with this project (please see my other post).