WebsiteBaker Support (2.8.x) > Bakery Shop
Last Items randomise products
daydreamer:
I know Last Items shows the latest added products first, is there anyway to make them randomise each time the page loads.
Thanks
freeSbee:
Hi Daydreamer
Test this:
Replace about line 113 of the include.php file
--- Code: ---$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);
--- End code ---
by
--- Code: ---$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);
--- End code ---
Be aware that this can take a large amount of processing time for table of more than 500 rows.
Regards Christoph
crnogorac081:
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: ---$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;
--- End code ---
Christoph may help you find the line where to insert shuffle function..
cheers
daydreamer:
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
daydreamer:
Just as an after thought could'nt this be added to bakery as another addon module "Show Random Products"
Regards
Nick
Navigation
[0] Message Index
[#] Next page
Go to full version