WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Bakery Shop => Topic started by: daydreamer on August 27, 2010, 08:03:30 PM

Title: Last Items randomise products
Post by: daydreamer on August 27, 2010, 08:03:30 PM
I know Last Items shows the latest added products first, is there anyway to make them randomise each time the page loads.
Thanks
Title: Re: Last Items randomise products
Post by: freeSbee on August 27, 2010, 11:07:45 PM
Hi Daydreamer

Test this:
Replace about line 113 of the include.php file
Code: [Select]
$query_items = $database->query("SELECT item_id, title, price, link, description, main_image FROM ".TABLE_PREFIX."mod_bakery_items WHERE active = '1' AND title != '' ORDER BY modified_when DESC LIMIT ".$num_items);
by
Code: [Select]
$query_items = $database->query("SELECT item_id, title, price, link, description, main_image FROM ".TABLE_PREFIX."mod_bakery_items WHERE active = '1' AND title != '' ORDER BY RAND() DESC LIMIT ".$num_items);

Be aware that this can take a large amount of processing time for table of more than 500 rows.

Regards Christoph
Title: Re: Last Items randomise products
Post by: crnogorac081 on August 27, 2010, 11:31:52 PM
I belive that the replaced line would display random X rows from items (ordered descending by any DB field name), and not LAST X rows

Try to adjust your code to
Code: [Select]
$query_items = $database->query("SELECT item_id, title, price, link, description, main_image FROM ".TABLE_PREFIX."mod_bakery_items WHERE active = '1' AND title != '' ORDER BY modified_when DESC LIMIT ".$num_items);
while($row = $query_items->fetchRow())
{
// Display and style your block here
$results2= "item id: ".$row['item_id']." title: ".$row['price']." link: ".$row['link']." description: ".$row['description']." image: ".$row['main_image'];

//THIS FUNCTION WILL SHUFFLE ORDER OF YOUR LAST ROWS SELECTED FROM DB
shuffle($results2);

// display array of items..
echo $results2;

Christoph may help you find the line where to insert shuffle function..

cheers
Title: Re: Last Items randomise products
Post by: daydreamer on August 28, 2010, 11:47:52 AM
Hi guys,

Many thanks for the help the first line seems to work fine, thanks Christoph

@crnogorac081

I replaced with you your to try that and it shows syntax error but I'm not sure why as I'm not a coder

Many Thanks
Nick

Title: Re: Last Items randomise products
Post by: daydreamer on August 28, 2010, 11:53:02 AM
Just as an after thought could'nt this be added to bakery as another addon module "Show Random Products"

Regards
Nick
Title: Re: Last Items randomise products
Post by: snark on September 04, 2010, 02:54:27 PM
What would be very nice is THE option to mark an item to be displayed

Something like THE groups option in news so that you can decide what to display in an anyitem sort of snipper