-Jeff- Posted October 18, 2007 Share Posted October 18, 2007 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 More sharing options...
Gauravs Posted October 18, 2007 Share Posted October 18, 2007 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 More sharing options...
-Jeff- Posted October 18, 2007 Author Share Posted October 18, 2007 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 More sharing options...
Gauravs Posted October 18, 2007 Share Posted October 18, 2007 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 More sharing options...
Gauravs Posted October 22, 2007 Share Posted October 22, 2007 $names = explode(" ", $first&lastname); echo $names[1]; in this case, $names[0] - would store first name and $names[1] would store last name... HTH, Best Regards,Gaurav Link to comment Share on other sites More sharing options...
-Jeff- Posted November 9, 2007 Author Share Posted November 9, 2007 $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 More sharing options...
Gauravs Posted November 9, 2007 Share Posted November 9, 2007 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 More sharing options...
-Jeff- Posted November 9, 2007 Author Share Posted November 9, 2007 Thanks!!! http://shop.livingstonestudio.com/ (artist dropdown on bottom left - there is manufacturer name in there that is three words right now, but if I can simply figure out how to get the includes/boxes/manufacturers.php to sort the dropdown by the second word = last name for the artists, I would be very very happy) Link to comment Share on other sites More sharing options...
Gauravs Posted November 10, 2007 Share Posted November 10, 2007 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 More sharing options...
-Jeff- Posted November 10, 2007 Author Share Posted November 10, 2007 Thank you! Thank you! Thank you! Your amazing coding and generosity spending the time to solve this is very much appreciated! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.