Bakery: LastItems - Image collection wrong

Gast

include.php from the last-item-snippet - maybe it works, if you remove the red marked part in this select

Quote// Query items
                $query_items = $database->query("SELECT item_id, title, price, link, description FROM ".TABLE_PREFIX."mod_bakery_items WHERE active = '1' AND title != '' ORDER BY modified_when DESC LIMIT ".$num_items);

from my point, its the best, if you rename the addon in info.php and in the function-name (display_last_items), so that you have a new addon

info.php
$module_directory     = 'lastitems';
$module_name          = 'Bakery Lastitems';


include.php
Quoteif (!function_exists('display_last_items')) {
        function display_last_items($num_items, $num_cols, $use_lightbox2 = 0) {

CodeALot

Thanks for your throrough explanation, but the problem is that I just want the script to show the position:1 image and not the latest or last modified.

But like I said: in the Bakery script it says:
$dir = dir($img_dir);
while (false !== $image_file = $dir->read()) {

It seems to me that this part of the script should not be there at all?

Gast

the first part in simple words:
read all information from table bakery-images, where position== 1 and active ==1 and add the results to an array, called $imgs

now you have a list with all possible images,
if you want, add here a output for the list behind this select like to read this array

$query_images = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_bakery_images WHERE position = '1' AND active = '1'");
                while ($img = $query_images->fetchRow()) {
                        $imgs[$img['item_id']] = $img;
                }
                echo "<pre>";
                print_r( $imgs );
                echo "</pre>";


the second part
take all infos from the items-table, order by the modified_when-timestamp  and build another list, check the adresses and build some paths to the pictures etc. now take from this second list only this pics , which also  part of the first array.
add this pictures to the new arrays IMAGES && THUMBS

the second code part in your post make sure, that you have only infos in the second array, where the path and pictures are readable.

so, the snippet does'nt show the last pictures, it show the "main" pics from the last modified items

thats my description. i dont use bakery in the moment, so not sure, that you change the modified_when-status in the items-table for a special item, if you add there only a new picture, maybe it works only, when you modify the description there.
maybe, you can check this in the items-table via PHPmyAdmin, MysqlDumper etc. order the output list to the row "modified_when" ASC or DESC, look to the item_id from the entry in the first line.
Now add a picture only to a different item and look again to the list

CodeALot

In include.php of LastItems I see this:

$imgs = array();
$query_images = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_bakery_images WHERE position = '1' AND active = '1'");
while ($img = $query_images->fetchRow()) {
$imgs[$img['item_id']] = $img;
}


But further on, I see that this script simply reads ALL images in the directory of the item, and displays the LAST image it finds, so not the "position:1"-image:

$dir = dir($img_dir);
while (false !== $image_file = $dir->read()) {


What am I overlooking? As soon as I add more images to an article in the Bakery Shop, the image shown in LastItems is NOT the position:1 image, but simply the last one I added.