Hi!
Basically, I have an image carousel in which each image is dynamically associated with the product. I have a script that reads a directory, saves the file names in an array. Then I crop the file extension, query the database for the article in which I want the image to link, by searching for the article with the same / similar name. for example: blets.jpg links to a full article. So I got this job.
But what I would like to do is be able to duplicate the images in the order that my articles assigned them in the ordering column.
What I now receive images and displays them in alphabetical order, what I'm trying to do is show them in the order that I assigned to my articles.
So here is my code:
echo "<div id='carousel'>\n"; // Get image file name // open directory $myDirectory = opendir("./images/products/carousel/spring-summer-2011/"); while($fileName = readdir($myDirectory)) // get each file { $dirArray[] = $fileName; } closedir($myDirectory); // close directory //sort($dirArray); // sort files echo "<div class='infiniteCarousel'> <div class='wrapper'> <ul>\n"; foreach ($dirArray as $file) { if (substr("$file", 0, 1) != ".") //don't list hidden files { $name = substr($file, 0, strrpos($file, '.')); // trim file name extension $res = mysql_query("Select id, alias, ordering from content where alias like '{$name}' ORDER BY ordering"); // order by is pretty useless here !! while ($row = mysql_fetch_array($res)) { $id = $row['id']; $alias = $row['alias']; $ordering = $row['ordering']; echo "<li><a href='index.php?option=com_content&view=article&id={$id}' title='{$alias}'>\n"; echo "<img src='./images/products/carousel/spring-summer-2011/{$file}' height='80' width='120' alt='{$alias}' />"; echo "</a></li>\n"; } } } echo "</ul>\n</div>\n</div>\n"; echo "</div>"; //Close Carousel
I left my comments in the code. And I basically know what to do, just not sure how to do it. I need a professional! help.
source share