Page 1 of 1

Need to Reverse the Order of images imported from DB

Posted: Wed Sep 08, 2010 7:35 pm
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

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

Posted: Wed Sep 08, 2010 7:42 pm
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