Jump to content
Sign in to follow this  
Dr. Mary Calaveris

CE-Phoenix-master 1.0.5.5: Wishing to show a random list of products on the 'products_new.php'

Recommended Posts

Running CE-Phoenix-master 1.0.5.5 and wishing to show a random list of products on the 'products_new.php' - but have been unsuccessful. Please check to see what it is I may be doing wrong with the code. Thanks.

1) Found this code on line 46-50.

  if ( (!isset($_GET['sort'])) || (!preg_match('/^[1-8][ad]$/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
      if ($column_list[$i] == 'PRODUCT_LIST_ID') {
        $_GET['sort'] = $i+1 . 'd';
        $listing_sql .= " order by p.products_id DESC";

2) Changed to

  if ( (!isset($_GET['sort'])) || (!preg_match('/^[1-8][ad]$/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
      if ($column_list[$i] == 'PRODUCT_LIST_ID') {
        $_GET['sort'] = $i+1 . 'RANDOM';
        $listing_sql .= " order by RAND()";
 

Share this post


Link to post
Share on other sites

Perhaps

  if ( (!isset($_GET['sort'])) || (!preg_match('/^[1-8][ad]$/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > count($column_list)) ) {
    $listing_sql .= " ORDER BY RAND()";
    for ($i=0, $n=count($column_list); $i<$n; $i++) {
      if ($column_list[$i] == 'PRODUCT_LIST_ID') {
        $_GET['sort'] = $i+1 . 'RANDOM';

Note that it is relatively easy to overwhelm this form of random ordering.  I think the limit is somewhere in the range of a hundred products (total in the store).  And of course paging won't work so well.  Because the second page will have a different random order from the first.  You can fix the paging issue with something like

    if (!isset($_SESSION['RANDOM_SEED'])) {
      $_SESSION['RANDOM_SEED'] = mt_rand();
    }
    $listing_sql .= " ORDER BY RAND(" . (int)$_SESSION['RANDOM_SEED'] . ")";

That will give a consistent ordering.  

Beyond that would need development.  There isn't a quick solution by editing a few lines. 

 


Always back up before making changes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×