Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How can I alphabatize the manufacturer list with artists' names by last name?


-Jeff-

Recommended Posts

My manufacturer list is actually a list of artists and craftspeople in the form First-Name Last-Name

 

Is there any way to alphabetize the manufacturer list / dropdown by the artists' last name instead of by their first name?

Link to comment
Share on other sites

Is there any way to alphabetize the manufacturer list / dropdown by the artists' last name instead of by their first name?

This is the default query used for showing manufacturers.

  $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

In your case, i am not sure how names have been stored in database (with First name / last name)

Check query in your installation (\includes\boxes\manufacturers.php) and tweak it to ORDER BY LAST_NAME(which ever column is available with you)

 

Cheers,

GS

Best Regards,
Gaurav

Link to comment
Share on other sites

This is the default query used for showing manufacturers.

  $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

In your case, i am not sure how names have been stored in database (with First name / last name)

Check query in your installation (\includes\boxes\manufacturers.php) and tweak it to ORDER BY LAST_NAME(which ever column is available with you)

 

Cheers,

GS

Right now the artist names have simply been added from the OSC admin interface in the single blank as

 

John Doe

Jim Smith

Adam Zork

 

Is there any "easy way out" magic code to skip the first word and sort on the last word before/while doing the mysql sort by manufacturer? (with both names in one field)?

Link to comment
Share on other sites

Right now the artist names have simply been added from the OSC admin interface in the single blank as

 

John Doe

Jim Smith

Adam Zork

 

Is there any "easy way out" magic code to skip the first word and sort on the last word before/while doing the mysql sort by manufacturer? (with both names in one field)?

Not difficult, but I can point you on how to do it .. lack of time to do it at this stage.

Since first name could be any no. of characters, use PHP function - substr() to chop down the name and then sort.

 

cheers

GS

Best Regards,
Gaurav

Link to comment
Share on other sites

  • 3 weeks later...
$names = explode(" ", $first&lastname);
echo $names[1];

in this case, $names[0] - would store first name and $names[1] would store last name...

HTH,

Thanks very very much. But I'm afraid I'm still not smart enough to get this -- if you have any time could you give me a little more code to achieve the manufacturers_name split, sort, and array before creating the dropdown in manufacturers.php

 

Thanks so much for sharing your knowledge.

Link to comment
Share on other sites

I almost forgot about this thread ... was asleep for a while :)

Send me the link to your site, and let me see what are the current names, and then how to go about modifying the code. I would check what can be done.

Best Regards,
Gaurav

Link to comment
Share on other sites

Hi Jeff,

Here is what you need to do

A. Do take a back up of /catalog/includes/boxes/manufacturers.php before making any changes, to ensure a roll back :)

 

B. Open in notepad and modify code as show below (this is on line # 13 ... )

 

// Original Query 
//  $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

// Order by Last Name instead of order by First Name, Use Substring and space for separation
 $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by substr( manufacturers_name, instr( manufacturers_name, ' ' ) ) DESC");

 

You may notice, that only difference is to replace

. " order by manufacturers_name");

by

. " order by substr( manufacturers_name, instr( manufacturers_name, ' ' ) ) DESC");

 

C. Next locate code shown below (this is else section to display names in drop down list.

else {
// Display a drop-down
  $manufacturers_array = array();
  if (MAX_MANUFACTURERS_LIST < 2) {
	$manufacturers_array[] = array('id' => '', 'text' => PULL_DOWN_DEFAULT);
  }

  while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
	$manufacturers_name = ((strlen($manufacturers['manufacturers_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ? substr($manufacturers['manufacturers_name'], 0, MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturers['manufacturers_name']);

$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
								   'text' => $manufacturers_name);
}

 

Replace with

else {
// Display a drop-down
  $manufacturers_array = array();
  if (MAX_MANUFACTURERS_LIST < 2) {
	$manufacturers_array[] = array('id' => '', 'text' => PULL_DOWN_DEFAULT);
  }

  while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
	$manufacturers_name = ((strlen($manufacturers['manufacturers_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ? substr($manufacturers['manufacturers_name'], 0, MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturers['manufacturers_name']);
$newname=explode(" ",$manufacturers_name); //<-- New Variable Introduced to split Names

/*		$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
								   'text' => $manufacturers_name);*/
	$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
								   'text' => $newname[1]." ".$newname[0]);  //<-- This is where you add them to display.

  }

 

You may review this code in action at my sandbox .

 

Good luck :)

Best Regards,
Gaurav

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...