Black Belt
- Join Date:
- Jul 2005
- Location:
- Upstate NY
- Posts:
- 21,874
- Plugin Contributions:
- 8
SQL question
Change this linephp if($col_count > $col_max_item){ to```php
if($col_count >= $col_max_item){
Black Belt
Change this linephp if($col_count > $col_max_item){ to```php
if($col_count >= $col_max_item){
Totally Zenned
PM sent
getting there, but the page isn't loading correctly, perhaps a </div> issue?
Black Belt
There are several issues, some styling-related, some missing code snippets from the reorganization, some due to there being no content for certain manufacturers, and some I don't understand yet.
I will have a modified bit for you soon, to handle the "no content" issue and a couple of others.
Totally Zenned
The ones with no content will be filled out as I update the products to fill out the fields that the code you've written uses.
if you replace page_4 with page_3 on the URL i've PM'd you you can see the running total of how many products i still have to update.
Totally Zenned
I hope i've not caused you too much of a headache working on this :)
Black Belt
Actually, I'm learning a bunch of stuff about working with objects and refreshing some of my PHP in general, so it's good for me (if a bit of a headache while I learn:).
I had to tweak the SQL to test it locally, because the pd.products_model_number field does not exist in stock ZC. I substituted products_model from the products table.
It seems that $unique_model is not just an array with products_model and manufacturers_id fields, but a whole stew of stuff, so sizeof() doesn't work on it, returning just 1. You have to use $unique_model->RecordCount() to get that info. That explains why other ZC files do a processing step on query results to put them into a usable array.
My latest version is here, and it appears to work in local testing.```php
<?php //test by gjh42 2010-11-17 - : http://www.zen-cart.com/forum/showthread.php?t=167959 second layout version - now updating in 139fresh //good for mfr lists that are all large // /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 $content = '<div id="modelList">' . "\n"; $manufacturers = $db->Execute("SELECT manufacturers_name, manufacturers_id FROM " . TABLE_MANUFACTURERS . " ORDER BY manufacturers_name ASC"); while (!$manufacturers->EOF) { $unique_model = $db->Execute("SELECT DISTINCT pd.products_model_number, p.manufacturers_id FROM " . TABLE_PRODUCTS_DESCRIPTION . " pd LEFT JOIN " . TABLE_PRODUCTS . " p ON pd.products_id = p.products_id WHERE p.manufacturers_id = '" . $manufacturers->fields['manufacturers_id'] . "' ORDER BY pd.products_model_number ASC"); //use this for stock zc //$unique_model = $db->Execute("SELECT DISTINCT products_model, manufacturers_id // FROM " . TABLE_PRODUCTS . " // WHERE manufacturers_id = '" . $manufacturers->fields['manufacturers_id'] . "' // ORDER BY products_model ASC"); $col_count = 0; $content .= '<div class="mfrList">' . "\n"; $content .= '<h3>' .$manufacturers->fields['manufacturers_name']. '</h3>' . "\n"; $um_size=($unique_model->RecordCount()); if($unique_model->RecordCount()>0) { $col_max_item = ceil($unique_model->RecordCount()/4); $content .= '<ul class="first">' . "\n"; while (!$unique_model->EOF) { if($col_count >= $col_max_item){ $col_count = 0; $content .= '</ul>' . "\n" . '<ul>' . "\n"; } $content .= ' <li><a href="index.php?main_page=advanced_search_result&search_in_description=1 keyword=' .$unique_model->fields['products_model_number']. '" alt="alt name" />' .$unique_model->fields['products_model_number']. '</a></li>' . "\n"; $col_count ++; $unique_model->MoveNext(); }//uniq $content .= '</ul>' . "\n"; }//size $content .= '<br class="clearBoth"></div>' . "\n"; $manufacturers->MoveNext(); }//man $content .= '</div><br class="clearBoth">' . "\n" . '</div>' . "\n"; echo $content; //EOF ?> <style> /*stylesheet rules*/ #modelList {} .mfrList {margin: 0.5em; padding: 0.5em; border-bottom: 1px solid #aabbcc;} #modelList h3 {text-align: center;} #modelList ul {float: left; width: 24.5%; margin: 0; padding: 0; border-left: 1px solid #aabbcc;} #modelList ul.first {border: none;} #modelList li {list-style: /*none*/ inside; padding: 0 0 0 1.0em;} #modelList a {color: #0099cc;} </style>
Totally Zenned
If you go to the same url I gave you before you can see the latest version, there still seems to be a problem with the page, I've had similar when there is one too many or not enough </div>
Totally Zenned
Fixed it I think, too last </div> out your code..
$content .= '</div><br class="clearBoth">' . "\n" . '</div>' . "\n";
echo $content;
//EOF
?>
became
$content .= '</div><br class="clearBoth">' . "\n" . '' . "\n";
echo $content;
//EOF
?>
Black Belt
It wasn't causing a visible problem on my test installation (define_page_4 content), but yes, there was an extra </div> in there. That and its accompanying <br class="clearBoth" /> can be deleted from the file.
Black Belt
I see you are still getting a single blank first item in most but not all of the lists. My test (using the ZC demo items & mfr's) does not do this.
Maybe it is caused by blank but not empty fields in your table?
Totally Zenned
Adjusted the style slightly.
The blank first item is due to not having all the fields completed yet for all products. So there are blank fields that need filling in, once they are filled in the blank first item will not be there.
It seems to be working perfectly now, I can't thank you enough!
Black Belt
Glad to hear that:) It's looking good. I can see this being useful for others, so I plan to package it up as a mod (with three variants) and submit it to Free Addons.
Totally Zenned
I agree I think it will be quite a useful addition.
Thank you for you work, and if you ever need anything from my store just send me a PM on here :)
Totally Zenned
I had a thought, but it depends how brave you are feeling :)
What if the products_model_number section was hidden by default and expanded by clicking on the manufacturers name?
Kind of like that, http://www.plus2net.com/javascript_tutorial/hide-layer.php
but when you click the model numbers slide down
perhaps like this?
http://www.dhtmlgoodies.com/index.html?whichScript=show_hide_content_slide
http://www.dhtmlgoodies.com/scripts/show-hide-content-slide/show-hide-content-slide.html
http://www.dhtmlgoodies.com/scripts/show-hide-content-slide/show-hide-content-slide-horizontal.html
Black Belt
A click/slide-down would take javascript (at least until CSS3 goodies are widely supported in browsers), but a hover/dropdown could be achieved with just currently available CSS, similar to flyout menus. I don't know much javascript and will not be learning it for this. I'll take a look at a CSS feature option.
Totally Zenned
Was just an idea as mine will be quite a long list, and if someone else has a long list it would make navigation easier.
Black Belt
A very easy way to do this is to add these two rules to the bottom of your modelList rule set:```
.mfrList ul {display: none;}
.mfrList:hover ul {display: block;}
Not a smooth transition, but effective at saving space.
Black Belt
By adding a wrapper div around the <ul> lists, you can have a dropdown that doesn't shift the following rows. Replace the center section of code with this```php
$um_size = ($unique_model->RecordCount());
if($um_size) {
$col_max_item = ceil($um_size/4);
$content .= '<div class="mfrListCols"><ul class="first">' . "\n";//added div
while (!$unique_model->EOF) {
if($col_count >= $col_max_item){
$col_count = 0;
$content .= '</ul>' . "\n" . '<ul>' . "\n";
}
$content .= ' <li><a href="index.php?main_page=advanced_search_result&search_in_description=1 keyword=' .$unique_model->fields['products_model_number']. '" alt="alt name" />' .$unique_model->fields['products_model_number']. '</a></li>' . "\n";
$col_count ++;
$unique_model->MoveNext();
}//uniq
$content .= '</ul></div>' . "\n";//added /div
}//size
and modify stylesheet rules```
<style>
/*stylesheet rules*/
#modelList {}
.mfrList {margin: 0.5em; padding: 0.5em; border-bottom: 1px solid #aabbcc; position: relative;}
#modelList h3 {text-align: center;}
#modelList ul {float: left; width: 24.5%; margin: 0; padding: 0; border-left: 1px solid #aabbcc;}
#modelList ul.first {border: none;}
#modelList li {list-style: none; padding: 0 0 0 1.0em;}
#modelList a {color: #0099cc;}
#modelList .mfrList .mfrListCols {display: none;}
#modelList .mfrList:hover .mfrListCols {display: block; position: absolute; width: 100%; background: #ffffcc; padding: 0.5em 0; border-bottom: 1px solid #aabbcc;}
</style>
Totally Zenned
Have a look at that link I sent you before, the hover is behind the text not infront.
Black Belt
The demo products do not have enough items in a list to show up that fact. Add a z-index to correct it.
.mfrList:hover .mfrListCols {z-index: 100;
Tell staff why this post should be reviewed.