Need to Reverse the Order of images imported from DB

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
tysty7
Forum Newbie
Posts: 1
Joined: Wed Sep 08, 2010 7:22 pm

Need to Reverse the Order of images imported from DB

Post by tysty7 »

The code below brings images in from the database into a table, as you can see. I am desperately trying to have the import order reversed. I have tried a few things but to no avail, it may be that I was on the right track but my head is sore from banging it against the nearest wall. :banghead:

Can anyone tell me how to do it? I am not new to php, but I am also not under the "advanced" category, so please.. speak to me like i am retarded 8O

Code: Select all

<?php

include_once("db_connect.php");

$sql = "SELECT imageURL FROM commercial";
$result = mysql_query($sql);

$num=mysql_numrows($result);



$i=0;
while ($i < $num) {
    $imageURL=mysql_result($result,$i,"imageURL");
    //echo $imageURL.$i;
    $i++;
    echo '<td><a id="'.$i.'" name="'.$i.'"></a><a href="#'.$i.'"><img class="TipImg" src="'.$imageURL.'" alt="" title="" height="440" /></a></td>';
}

?>
Love,
Tyler
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Re: Need to Reverse the Order of images imported from DB

Post by mecha_godzilla »

You could reorder them either in your PHP code or the DB query; as an example, where you've got

Code: Select all

SELECT imageURL FROM commercial
you could change it to

Code: Select all

SELECT imageURL FROM commercial ORDER BY imageURL DESC
You could also use sort() in your PHP code - more details at:

http://uk.php.net/manual/en/function.sort.php

HTH,

Mecha Godzilla
Post Reply