ORDER by latest? (MYSQL)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xenoalien
Forum Newbie
Posts: 19
Joined: Fri Apr 04, 2008 12:11 pm
Location: Cyberspace

ORDER by latest? (MYSQL)

Post by xenoalien »

I have a database of wallpaper at http://www.wallpapersearch.net and would like to make the "latest" part of the website be based on a mysql query that orders by latest? Is this possible? At the top I have it order by rand or random.
Thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: ORDER by latest? (MYSQL)

Post by Christopher »

ORDER BY `add_date` DESC
(#10850)
xenoalien
Forum Newbie
Posts: 19
Joined: Fri Apr 04, 2008 12:11 pm
Location: Cyberspace

Re: ORDER by latest? (MYSQL)

Post by xenoalien »

arborint wrote:ORDER BY `add_date` DESC
I tried that and it gave my a query error.
This is what I did:
$query = "SELECT * FROM mytable ORDER BY `add_date` DESC LIMIT 0, 4";

This is how I have it now:
$query = "SELECT * FROM mytable ORDER BY RAND() LIMIT 0, 4";

I don't have a date column but I do have an "ID" (auto increment) column if that helps.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: ORDER by latest? (MYSQL)

Post by RobertGonzalez »

What is the name of the column you want to sort by?
xenoalien
Forum Newbie
Posts: 19
Joined: Fri Apr 04, 2008 12:11 pm
Location: Cyberspace

Re: ORDER by latest? (MYSQL)

Post by xenoalien »

Wall_ID

edit: Basically the highest id down. So if my highest number was 1234 I would want it to order from there to 1230 using limit.
xenoalien
Forum Newbie
Posts: 19
Joined: Fri Apr 04, 2008 12:11 pm
Location: Cyberspace

Re: ORDER by latest? (MYSQL)

Post by xenoalien »

*bump*
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: ORDER by latest? (MYSQL)

Post by Christopher »

:roll:
arborint wrote:ORDER BY `Wall_ID` DESC LIMIT 4
(#10850)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: ORDER by latest? (MYSQL)

Post by RobertGonzalez »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not receive a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
Please be aware of rules. Thank you.

In relation to your problem:

Code: Select all

<?php
$query = "SELECT * FROM mytable ORDER BY `Wall_ID` DESC LIMIT 0, 4";
?>
Try that and see what it does.
Post Reply