Forums / All Other Contributions/Addons / Random Display of Manufacturers Images

Random Display of Manufacturers Images

Locked

Started by doodlebee on 21 Nov 2008, 9:52 PM · Views: 1,058

Results 1 to 1 of 1
This thread is locked. New replies are disabled.
21 Nov 2008, 9:52 PM
#1
doodlebee avatar

doodlebee

Inactive

Join Date:
Jan 2006
Posts:
228
Plugin Contributions:
0

Random Display of Manufacturers Images

Hey all - I just thought I'd share this. I pieced it together form a few snippets of code I found here on the forums, as well as just piecing things together to get them to work like I needed them to.

So, the thing was that my client had several category pages with subcategories. Since you can't display products in the categories (unless it's the lowest level), he wanted something in the content area of the site when people were going through all the category pages. Mainly, he wanted product logos to show, but not ALL of them (because there were a LOT). But he didn't want the same logos on every page.

So I did something that pulled them in at random - so every time you loaded a category page, it would pull logos at random from the database and plop them in on the site. I'm hoping this helps someone else - because it took me a little while to pull all this together. I used this on the tpl_index_categories.php page, but I'd say you could pretty much put this piece of code anywhere you want random logos to show up. There is NO FORMATTING on this. It's basically a logo image, and it'll link to the products for that manufacturer. Styling is all up to you. So here we go:

<div id="manufacturerListImages">
<!--manufacturers image hack -->
<?php  $logos_query = "select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, mi.manufacturers_url
                           from " . TABLE_MANUFACTURERS . " m                           
                           left join " . TABLE_MANUFACTURERS_INFO . " mi
                           on m.manufacturers_id = mi.manufacturers_id
                           where 1
                           order by RAND() DESC LIMIT 5";

 $logos_result = $db->Execute($logos_query);

  while (!$logos_result->EOF) {

  	$logo_id = $logos_result->fields['manufacturers_id']; // get the manufacturer's ID
  	$man_name = $logos_result->fields['manufacturers_name']; // get the manufacturer's name
  	$logo = $logos_result->fields['manufacturers_image']; // get the manufacturer's image
 
 echo '<a href="index.php?main_page=index&manufacturers_id=' . $logo_id . '" title="view all products by ' . $man_name . '"><img src="' . HTTP_SERVER . DIR_WS_CATALOG . 'images/' . $logo . '" /></a>' . "\n";

   $logos_result->MoveNext();

  } ?> 
<!--eof manufacturers image hack -->
</div>

The code is set to randomly select 5 logos form the database (" order by RAND() DESC LIMIT 5";" line up there), but you can change the "5" to however many you want.

like I said, hope that helps someone else!