Author Topic: Last Items randomise products  (Read 2580 times)

daydreamer

  • Guest
Last Items randomise products
« 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

Offline freeSbee

  • Moderator
  • ***
  • Posts: 1117
    • BAKERY - Website Baker shop module
Re: Last Items randomise products
« Reply #1 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

Offline crnogorac081

  • Posts: 1908
  • Gender: Male
Re: Last Items randomise products
« Reply #2 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
« Last Edit: August 27, 2010, 11:51:13 PM by crnogorac081 »
no bb in signature

daydreamer

  • Guest
Re: Last Items randomise products
« Reply #3 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


daydreamer

  • Guest
Re: Last Items randomise products
« Reply #4 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

snark

  • Guest
Re: Last Items randomise products
« Reply #5 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