Does anyone know how to reverse the output of a MySQL query with PHP?
I tried storing it into an array and flipping, but no luck.
Any ideas?
Printable View
Does anyone know how to reverse the output of a MySQL query with PHP?
I tried storing it into an array and flipping, but no luck.
Any ideas?
This is what I had:
This is what I tried:PHP Code:<?php
$dbconnect = mysql_connect("localhost", ":norris:", ":norris:");
mysql_select_db(":norris:", $dbconnect);
$articles = mysql_query("SELECT * FROM Articles");
while ($row = mysql_fetch_array($articles))
{
print('<a class="pagetitle" href="' . $row['url'] . '">' . $row['title'] . ' </a>');
print("\n<br />\n");
print('<div class="creator">' . $row['creator'] . '</div>');
print("\n<br />\n");
print('<div class="description">' . $row['description'] . '</div>');
print("<hr>\n");
}
mysql_close($dbconnect);
?>
I want to make the query:PHP Code:<?php
$dbconnect = mysql_connect("localhost", ":norris:", ":norris:");
mysql_select_db(":norris:", $dbconnect);
$articles = mysql_query("SELECT * FROM Articles");
$temp = 0;
while ($row = mysql_fetch_array($articles))
{
$row['title'] = $title[$temp];
$row['description'] = $description[$temp];
$row['creator'] = $creator[$temp];
$row['url'] = $url[$temp];
$temp++;
}
$temp = 0;
while ($temp < count($title))
{
print('<a class="pagetitle" href="' . $url[$temp] . '">' . $title[$temp] . ' </a>');
print("\n<br />\n");
print('<div class="creator">' . $creator[$temp] . '</div>');
print("\n<br />\n");
print('<div class="description">' . $description[$temp] . '</div>');
print("<hr>\n");
}
mysql_close($dbconnect);
?>
Become:PHP Code:1
2
3
4
5
6
I can't store it into an array for some reason...PHP Code:6
5
4
3
2
1
Any ideas why?
Oops! Never mind...
I typed:
Instead of:PHP Code:$row['title'] = $title[$temp];
$row['description'] = $description[$temp];
$row['creator'] = $creator[$temp];
$row['url'] = $url[$temp];
Fixed!PHP Code:$title[$temp] = $row['title'];
$description[$temp] = $row['description'];
$creator[$temp] = $row['creator'];
$url[$temp] = $row['url'];
Thanks for making me type it out!
Can't you put "ORDER BY `title` DESC" in there?
It is a forum that I made.
It displayed the oldest topics first, and newest last.
I needed to flip it around.
Well then "ORDER BY `post_date` DESC"?
Just use ORDER BY <ENTITY1> [ENTITY2...] as Floor66 stated. Also, ASC = Ascending Order, Desc = descending order. Each Entity can be ASC or DESC.