without the actual code, it would be hard...if the articles are taken from a DB, use "order by" in the SQL command
If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.
Register Today on DNForum IT'S FREE!Hello
I have a piece of php to list the titles and descriptions of articles. When it prints the info out on the page, it puts the newest article at the bottom of the list and keeps on adding to the bottom.
Can someone please let me know if I could put a line in the php so the order is the opposite - the newest entries go to the first position and not the last.
thx so much for you time
without the actual code, it would be hard...if the articles are taken from a DB, use "order by" in the SQL command
If you can't solve this with SQL the php function array_reverse() might help you.
...
Web Hosting @ $4.95 a year, this offer will be active until July 31, 2009 11:59pm.
your sql statement should be
"ORDER BY `column` DESC"
or
"ORDER BY `column` ASC"
Change column to the column in your mysql like id, title etc
I really appreciate the responses guys. I am sorry I wasn't more specific. I should have really said up front that it is not an sql database.
I'll post the code which I should have done in the beginning :(
The articles just go into an article folder.
Here's the full code:
Thx again for helping.<?php
$folder = "/server path/domainnamehere.com/articles";
$dirhandle = opendir("$folder");
while($file_name = readdir($dirhandle)) {
if ($file_name != "."
&& $file_name != ".."
&& $file_name != "list.php"
&& $file_name != "index.html"
) {
// DO THIS FOR EACH FILE
// get contents of a file into a string
$filename = "$folder/$file_name";
$handle = fopen($filename, "rb");
$contents = fread($handle, 1000);
fclose($handle);
$matches = "";
// EXTRACT Title
if(preg_match("'<title>(.+)</title>'i", $contents, $matches)){
$title = $matches[1];
print("<div class=\"medium-header\"><A HREF=\"$file_name\">$title</A></div>");
$matches = "";
}
// EXTRACT Description
if(preg_match("'<META NAME=\"Description\" CONTENT=\"(.+)\">'i", $contents, $matches)){
$description = $matches[1];
print("$description<BR><BR><HR>");
$matches = "";
}
print("");
}
}
?>
Bookmarks