View Full Version : [PHP]Make XX First
loserWILL
14-02-2008, 10:41 PM
Ok, say I have some news articles that are displayed using mySQL and PHP.
When I add a new article, the newer one goes at the bottom. How do I make it so the newer one displays at the top.
Invent
14-02-2008, 11:38 PM
ORDER BY `lol` DESC
loserWILL
14-02-2008, 11:39 PM
what do I replace with 'lol'?
And if you want it to display only 5 then:
SELECT * FROM `news` ORDER BY `id` DESC LIMIT 0 , 5
loserWILL
14-02-2008, 11:44 PM
Gosh I'm a nub. :P
Where would I add that in this:
<?php
include "config.php";
$sql = "SELECT * FROM news";
$check = mysql_query("SELECT authour, title, news_content, date FROM news") or die("There is no news at the moment.");
while ($display = mysql_fetch_array($check)) {
$news_content = $display['news_content'];
$title = $display['title'];
$authour = $display['authour'];
$date = $display['date'];
echo "<h2>$title - <span>by $authour</span></h2>
<p>$news_content<br />
<strong><i>Posted on: $date</i></strong></p><br />
<br />
";
}
?>
NVM: Got it. Thank you Simon and Jack.
loserWILL
15-02-2008, 12:03 AM
Egh, the "DESC LIMIT 0 , 5" is causing me problems:
The firts news title is fine, but the second news article's title is shifted to the right When I removed that desc limit it's fine, but it doesn't order the news how I want it to.
Agnostic Bear
15-02-2008, 12:29 AM
[quote=loserWILL;4447420]Gosh I'm a nub. :P
$sql = "SELECT * FROM news";
What the hell do you keep putting that in there for it serves no purpose.
loserWILL
15-02-2008, 01:03 AM
I'll remove that.
Does anybody know the answer to the question I posted above?
SELECT * FROM `news` ORDER BY `news`.`id` ASC LIMIT 0 , 5
The `id` is what its ordering by.
loserWILL
15-02-2008, 02:18 AM
That doesn't order it properly, or at leats how I want it to order.
Invent
15-02-2008, 02:26 AM
SELECT * FROM `news` ORDER BY `id` DESC LIMIT 5
Unpredictible.1
15-02-2008, 02:38 AM
SELECT * FROM `news` ORDER BY `id` DESC LIMIT 5
thanks
That doesn't order it properly, or at leats how I want it to order.
oops, change ASC to DESC :)
loserWILL
15-02-2008, 03:12 AM
Simon & Jack, your code orders it properly (how I want it) but it screws up the title:
http://img158.imageshack.us/img158/7288/huhjr9.gif
DeejayMachoo$
15-02-2008, 07:53 AM
Simon & Jack, your code orders it properly (how I want it) but it screws up the title:
http://img158.imageshack.us/img158/7288/huhjr9.gif
sql doesn't affect the way its displayed on a page;
timROGERS
15-02-2008, 07:56 AM
That's your poor HTML I'm afraid :P
loserWILL
15-02-2008, 01:12 PM
It's fine wihout that sql code.
redtom
15-02-2008, 02:09 PM
It's fine wihout that sql code.
No it's not.
loserWILL
15-02-2008, 05:21 PM
It wasn't like that until I added that code?
DeejayMachoo$
15-02-2008, 05:50 PM
It wasn't like that until I added that code?
You must of mistakenly changed your html.
loserWILL
15-02-2008, 05:55 PM
I don't think so, as I've removed the code and it works fine again.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.