Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to change customer list sort order?


Guest

Recommended Posts

Posted

I DID search for this but it didn't come up in the first 65 pages of search results (and the results seemed to have nothing to do with my search string of customer sort join), so here goes.

 

I have two clients with stores that want to modify the order in which their customers show up on the list.

 

They want them to be listed by join date, not alphabetically as is the default.

 

How can this be changed?

 

Thanks

Posted

I only got 2 pages ;-) .... admittedly it was the last one on page 2

 

http://www.oscommerce.com/community/contri...,customers+sort

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Posted
I DID search for this but it didn't come up in the first 65 pages of search results (and the results seemed to have nothing to do with my search string of customer sort join), so here goes.

 

I have two clients with stores that want to modify the order in which their customers show up on the list.

 

They want them to be listed by join date, not alphabetically as is the default.

 

How can this be changed?

 

Thanks

 

Well, here is the meat of your problem...line 719 or so in admin/customers.php

 

$customers_query_raw = "select c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_email_address, a.entry_country_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_A0DRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search . " order by c.customers_lastname, c.customers_firstname";

$customers_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $customers_query_raw, $customers_query_numrows);

$customers_query = tep_db_query($customers_query_raw);

 

Here is the original query that sort by lastname, then first name. Your problem is that this query DOES NOT yet contain the date_account_created. THAT data is loaded during the execution of the loop that follows the above code...

 

 

while ($customers = tep_db_fetch_array($customers_query)) {

$info_query
= tep_db_query("select customers_info_date_account_created as date_account_created, customers_info_date_account_last_modified as date_account_last_modified, customers_info_date_of_last_logon as date_last_logon, customers_info_number_of_logons as number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $customers['customers_id'] . "'");

So now, you have two chunks of data...an multi-dimsional assocative array of all the customers in the database, sorted by lastname ($customers_query) and a string ($info_query), that holds the the data YOU want to sort by (date_account_created).

 

So what to do? Few ways to handle this...maybe you could loop through all the $customer_query entries and append the date_account_created data to the end of each existing row, and use some sort of PHP array_sort command to rearrange the data BEFORE sending it to the loop.

 

Here is the psuedo-code.

 

// load $customer_query

$idx = 0;

while ($customers = tep_db_fetch_array($customers_query)) {

$info_query
= tep_db_query("select customers_info_date_account_created as date_account_created, customers_info_date_account_last_modified as date_account_last_modified, customers_info_date_of_last_logon as date_last_logon, customers_info_number_of_logons as

number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $customers['customers_id'] . "'");

// $customers_query[$idx]['c.date_created'] = $info_query;

$idx = $idx +1;

}

 

Then use array_multisort() to resort $customers_query using the new field, THEN run $customers_query through the next steps.

 

Hope this helps..

Archived

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

×
×
  • Create New...