I was bothered by the inefficient use of SQL queries (one per manufacturer, plus one; could be dozens or hundreds of queries just for this list), so I did some studying of MySQL and recoded it to operate with just one query to fetch all the information. It is then processed into a multi-level array, which is output to the set of lists as before. I have added some defines for flexibility.
As posted, it will give a vertical manufacturer list with dropdown product lists in three columns, but with a define change and a few styling changes, it will be a horizontal manufacturer list with dropdown vertical product lists.
PHP Code:
<?php
//test by gjh42 2010-11-30 - working: http://www.zen-cart.com/forum/showthread.php?t=167959 second sql/code version - now updating in 139fresh
// /includes/modules/your_template/model_list2.php
// include(DIR_WS_MODULES . zen_get_module_directory(model_list2.php));//put in location file - not working
// include(DIR_WS_MODULES . 'your_template/model_list2.php');//put in location file
//includes/languages/english/extra_definitions/your_template/model_list_defines.php
define('MODEL_LIST_COLS', 3);
define('MODEL_LIST_EMPTIES', '');//to eliminate empty mfr lists comment this and uncomment next line
//define('MODEL_LIST_EMPTIES', ' and p.products_model IS NOT NULL');
define('MODEL_LIST_MFR_COMMENT', '<br /><span class="mfrComment"> hover for models</span>');
define('MODEL_LIST_ALT_LINK', 'Click to search for ');
//EOF defines
$model_list_sql = 'SELECT DISTINCT p.products_model, p.manufacturers_id, m.manufacturers_name
FROM ' . TABLE_PRODUCTS . ' p, ' . TABLE_MANUFACTURERS . ' m
WHERE m.manufacturers_name IS NOT NULL
AND p.manufacturers_id = m.manufacturers_id' . MODEL_LIST_EMPTIES . '
ORDER BY m.manufacturers_name, p.products_model';
$model_list_query = $db->Execute($model_list_sql);
$current_mfr = '';
while (!$model_list_query->EOF) {
if ($model_list_query->fields['manufacturers_name'] != $current_mfr) {
$current_mfr = $model_list_query->fields['manufacturers_name'];
$model_list[$current_mfr]['mfrs_id'] = $model_list_query->fields['manufacturers_id'];
}
$model_list[$current_mfr]['products_model'][] = $model_list_query->fields['products_model'];
$model_list_query->MoveNext();
}
$content = '<div id="modelList">' . "\n";
foreach ($model_list as $mfr_key=>$current_mfr) {
$col_count = 0;
$mfrs_name = $mfr_key;
$content .= '<div class="mfrList">' . "\n";
$content .= '<h3><a href="index.php?main_page=advanced_search_result&search_in_description=1&keyword=' . $mfrs_name . '" title="' . MODEL_LIST_ALT_LINK . $mfrs_name . '">' . $mfrs_name . '</a>' . MODEL_LIST_MFR_COMMENT . '</h3>' . "\n";
$list_size = count($model_list[$mfr_key]['products_model']);
if($list_size) {
$col_max_item = ceil($list_size/MODEL_LIST_COLS);
$col_width = ' style="width:' . 99/MODEL_LIST_COLS . '%;"';
$content .= '<div class="mfrListCols"><ul class="first"' . $col_width . '>' . "\n";
for ($i=0;$i<$list_size;$i++) {
if($col_count >= $col_max_item){
$col_count = 0;
$content .= '</ul>' . "\n" . '<ul' . $col_width . '>' . "\n";
}
$current_model = $model_list[$mfr_key]['products_model'][$i];
$content .= ' <li><a href="index.php?main_page=advanced_search_result&search_in_description=1&keyword=' . $current_model . '" title="' . MODEL_LIST_ALT_LINK . $current_model . '">' . $current_model . '</a></li>' . "\n";
$col_count ++;
}
$content .= '</ul></div>' . "\n";
}//size
$content .= '<div class="clearBoth"></div></div>' . "\n";
}//foreach
$content .= '</div>' . "\n";
echo $content;
//EOF
?>
<style>
/*stylesheet rules*/
#modelList {}
.mfrList {margin: 0; padding: 0; border-bottom: 1px solid #aabbcc; position: relative; /*float: left; width: 33%;*/}
#modelList h3 {text-align: left;}
#modelList h3 a {}
.mfrComment {font-size: 0.7em; font-weight: normal; color: #aabbcc; margin-left: 1.0em;}
#modelList ul {float: left; margin: 0; padding: 0;}
#modelList ul.first {}
#modelList li {list-style: inside; padding: 0 0 0 0.2em; color: #990000;}
#modelList a {color: #0099cc;}
.mfrListCols {display: none;}
.mfrList:hover .mfrListCols {display: block; position: absolute; z-index: 100; width: 98.7%; background: #ffffee; padding: 0.5em 0 0.5em 0.5em; border-bottom: 1px solid #aabbcc;}
</style>
Once it has a bit more testing by others, I will separate it out into the proper component files and package it up as a mod. Please let me know if you test it.