Forums / General Questions / SQL question

SQL question

Locked

Started by digitalshadow on 10 Nov 2010, 7:47 PM · Views: 4,491

Results 61 to 68 of 68
This thread is locked. New replies are disabled.
18 Nov 2010, 8:23 PM
#61
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

SQL question

Change your ist-style to inside to get your bullets contained inside the dropdown background.

#modelList ul {float: left; width: 24.5%; margin: 0; padding: 0; border-left: 1px solid #aabbcc;list-style: inside;}

18 Nov 2010, 8:34 PM
#62
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: SQL question

Done that, have a look....

18 Nov 2010, 8:37 PM
#63
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: SQL question

What happened? It worked fine when I tested it on your site.

You didn't just drop in that bit verbatim, did you? It was intended to show where to add the property to the existing rule, and the absense of a closing } would cause problems as a standalone rule.

18 Nov 2010, 8:46 PM
#64
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: SQL question

try now, I was adjusting the code.

I presume that search engines will be able to read it just the same even though it is hidden?

18 Nov 2010, 9:19 PM
#65
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: SQL question

On a side note what you think of the site? I've not ever put it up for critique, but feedback is welcome.

18 Nov 2010, 10:00 PM
#66
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: SQL question

Why that's beeyoutyful! (As a boss of mine used to say:) Very nice styling of the list, and works great. The alt text is well used.

I'm not a search engine expert, but I don't think they will have problems seeing the links. Dropdown CSS category menus like this are widely used.

The site overall is gorgeous. The fixed fall foliage/sky background sets a pleasant tone just being on the site, and the functional parts are stylish but unobtrusive. I haven't looked all around the site, but what I have seen looks clear, informative and easy to use.

1 Dec 2010, 2:43 AM
#67
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: SQL question

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

<?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.
6 Dec 2010, 11:56 PM
#68
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: SQL question

Model List has been submitted to Free Addons. The support thread and interim location of the zip is here.

I have added the ability to display either product names or model numbers (sorted alphabetically in either case).