Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Order by date

Featured Replies

Hello everyone,

Currently creating a my orders page for the shop on my website.

I learned the hard way that you shouldn't use just 1 field for the date but need separates for day month and year because when you have 01/01/2018 it doesn't work order after the /.

So this seems to work:

	SELECT *, (ORDERDAY+ORDERMONTH+ORDERYEAR) AS total FROM SHOPORDERS WHERE USERID = '$dbget_id' ORDER BY total DESC
	

Is the code above the correct way to order them?

image.thumb.png.1a10a15eb4f991d5ed4e5faef05ab83e.png

Edit:

I think this did the trick:

	SELECT *, (DATE(ORDERYEAR)+DATE(ORDERMONTH)+DATE(ORDERDAY)) AS date FROM SHOPORDERS WHERE USERID = '$dbget_id' ORDER BY date DESC
	

Edited by ChubbyKakert

  • Author

There still seems to be something wrong.

This is the code:

	$getordersquery = $db->query("SELECT *, (DATE(ORDERYEAR)+DATE(ORDERMONTH)+DATE(ORDERDAY)) AS date FROM SHOPORDERS WHERE USERID = '$dbget_id' ORDER BY date ASC");

I tried both DESC and ASC but the results are the same. What am i doing wrong?

image.thumb.png.ce578c5a466894acaa27b7a5f994ced5.pngPlease don't pay attention to the date format. There should be only a yesterday or today on the date but i have the full date for testing purposes. I know that i could use the Order ID to order them but i think doing it on date would be better and useful cause i will need it for the forums too etc.

It's because of the date format, you need it to become year-month-day hour:minutes:seconds. Not sure how far through you are but you should be storing the correct date and time format in the database as a DATE/TIME Data Type. Then you can make simple SQL requests where date is between two dates, show time in the persons current timezone and more.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.