HI !
Basically I have an image carousel that, where each image is linked to article dynamically.
I have a script that reads the directory, store the file names into an array.
Then I trim off the file extension, query the database for the article I want the image to link to by searching for the article with the same/ similar name.
e.g: blets.jpg links to the belts article.
SO I got that working.
But what I would like to do is be able to have the images be diplayed in the order my articles have assigned to them in the ordering column.
What I have now fetches the images and displays them alphabetically, what I ‘m trying to do is have them displayed in the order I have assigned to my articles.
So here’s 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’ve left my comments in the code.
And I basically know what needs to be done, just not sure how to do it.
I need a pro !? help.
1 Answer