Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sort order by model number in product listing


minghoo

Recommended Posts

Posted

Hi guys,

 

i just figured out how to sort product by model number.

 

i searched this forum a whole afternoon, didn't get what i want.

 

index.php find code:

 

    if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
     for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
       if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
         $HTTP_GET_VARS['sort'] = $i+1 . 'a';
         $listing_sql .= " order by pd.products_name";
         break;
       }
     }

 

 

you need to change three places;

1. change $i+1 to $i-1,

2. change 'PRODUCT_LIST_NAME' to 'PRODUCT_LIST_MODEL',

3. change order by pd.products_name to order by p.products_model

 

so the whole code should be:

 

if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
     for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
       if ($column_list[$i] == 'PRODUCT_LIST_MODEL') {
         $HTTP_GET_VARS['sort'] = $i-1 . 'a';
         $listing_sql .= " order by p.products_model desc";
         break;
       }
     }

 

if you only change 2 and 3 place, it won't work on 2 or 3 pages.

 

If anyone has problem, please just post.

Posted
Hi guys,

 

i just figured out how to sort product by model number.

 

i searched this forum a whole afternoon, didn't get what i want.

 

index.php find code:

 

 ? ?if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
? ? ?for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
? ? ? ?if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
? ? ? ? ?$HTTP_GET_VARS['sort'] = $i+1 . 'a';
? ? ? ? ?$listing_sql .= " order by pd.products_name";
? ? ? ? ?break;
? ? ? ?}
? ? ?}

you need to change three places;

1. change $i+1 to $i-1,

2. change 'PRODUCT_LIST_NAME' to 'PRODUCT_LIST_MODEL',

3. change order by pd.products_name to order by p.products_model

 

so the whole code should be:

 

if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
? ? ?for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
? ? ? ?if ($column_list[$i] == 'PRODUCT_LIST_MODEL') {
? ? ? ? ?$HTTP_GET_VARS['sort'] = $i-1 . 'a';
? ? ? ? ?$listing_sql .= " order by p.products_model desc";
? ? ? ? ?break;
? ? ? ?}
? ? ?}

 

if you only change 2 and 3 place, it won't work on 2 or 3 pages.

 

If anyone has problem, please just post.

Hello minghoo,

 

I did exactly as you say, changed code in all 3 places, but I still get my products listed by products_name on index.php. Did I miss anything?

 

Thanks,

Irina.

  • 2 weeks later...
Posted

The code as shown in the body of the message is correct, the code in the "code" box is incorrrect -- change #3 to p.products_model, NOT p.products_model desc

DAN

 

 

 

Hello minghoo,

 

I did exactly as you say, changed code in all 3 places, but I still get my products listed by products_name on index.php. Did I miss anything?

 

Thanks,

Irina.

Posted

The code as shown in the body of the message is correct, the code in the "code" box is incorrrect -- change #3 to p.products_model, NOT p.products_model desc

DAN

Hello minghoo,

 

I did exactly as you say, changed code in all 3 places, but I still get my products listed by products_name on index.php. Did I miss anything?

 

Thanks,

Irina.

Unfortunately it doesn't work with neither p.products_model nor p.products_model desc. I tried both of them but nothing changed.

 

Any other ideas?

Thanks.

  • 10 months later...
  • 1 year later...
  • 1 month later...
Posted
am having trouble with this modification not properly organizing products on pages of products other than page 1

I am also having the same problem, I order my products list by model number. On the first page it seems fine, but when I click next, all my products are jumbled in a reverse order, it is causing 5 of my products to never show up. Is there a way to list all products on the same page without clickng next??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...