Forum Moderators: coopster
<?php
/*
$Id: random_products.php,v 1.31 2003/02/10 22:31:09 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
$random_products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' order by rand() limit " . MAX_RANDOM_SELECT_SPECIALS);
//$random_products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id left join " . TABLE_FEATURED . " f on p.products_id = f.products_id where p.products_status = '1' and f.status = '1' order by rand() limit " . MAX_RANDOM_SELECT_SPECIALS);
if ( $random_products_query ) {
$random_products_script = '<script type="text/javascript" src="js/prototype.js"></script>' . "\n";
$random_products_script .= '<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>' . "\n";
//$random_products_script .= '<script type="text/javascript" src="js/display_random_products.js"></script>' . "\n";
$random_products_script .= '<script type="text/javascript">' . "\n";
$random_products_script .= 'var randomProductIndex = 0;' . "\n";
$random_products_script .= 'var randomProductArray = new Array();' . "\n";
$random_products_script .= 'function showRandomProduct() {' . "\n";
$random_products_script .= "Effect.Appear( 'randomProductDiv', { duration: 1.0 } );\n";
$random_products_script .= "setTimeout( 'loadRandomProduct()', 3000 );\n";
$random_products_script .= '}' . "\n";
$random_products_script .= 'function loadRandomProduct() {' . "\n";
$random_products_script .= "Element.hide('randomProductDiv');\n";
$random_products_script .= "var randomProductDiv = document.getElementById('randomProductDiv');\n";
$random_products_script .= 'var href = randomProductArray[randomProductIndex][0];' . "\n";
$random_products_script .= 'var src = randomProductArray[randomProductIndex][1];' . "\n";
$random_products_script .= 'var w = randomProductArray[randomProductIndex][2];' . "\n";
$random_products_script .= 'var h = randomProductArray[randomProductIndex][3];' . "\n";
$random_products_script .= 'var name = randomProductArray[randomProductIndex][4];' . "\n";
$random_products_script .= 'var price = randomProductArray[randomProductIndex][5];' . "\n";
$random_products_script .= 'var sprice = randomProductArray[randomProductIndex][6];' . "\n";
$random_products_script .= 'var loaded = randomProductArray[randomProductIndex][7];' . "\n";
$random_products_script .= "var text = '';\n";
$random_products_script .= "text += '<a href=\"' + href + '\">';\n";
$random_products_script .= "text += '<img src=\"' + src + '\" width=\"' + w + '\" height=\"' + h + '\" border=\"0\" alt=\"' + name + '\" title=\"' + name + '\"';\n";
$random_products_script .= "text += ' onload=\"randomProductArray[' + randomProductIndex + '][7]=true;showRandomProduct()\"';\n";
$random_products_script .= "text += '>';\n";
$random_products_script .= "text += '</a><br>';\n";
$random_products_script .= 'if ( sprice.length > 0 ) text += sprice;' . "\n";
$random_products_script .= 'else text += price;' . "\n";
$random_products_script .= "randomProductDiv.innerHTML = text;\n";
$random_products_script .= 'randomProductIndex++;' . "\n";
$random_products_script .= 'if ( randomProductIndex >= randomProductArray.length ) randomProductIndex = 0;' . "\n";
$random_products_script .= '}' . "\n";
while ($f = tep_db_fetch_array($random_products_query)) {
tep_image(DIR_WS_IMAGES . $f['products_image'], '', SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
$random_products_script .= 'randomProductArray.push( new Array(';
$random_products_script .= "'" . tep_href_link( FILENAME_PRODUCT_INFO, 'products_id=' . $f["products_id"] ) . "',";
$random_products_script .= "'" . DIR_WS_IMAGES . $f['products_image'] . "',";
$random_products_script .= "'" . SMALL_IMAGE_WIDTH . "',";
$random_products_script .= "'" . SMALL_IMAGE_HEIGHT . "',";
$random_products_script .= "'" . mysql_escape_string($f['products_name']) . "',";
$random_products_script .= "'" . $currencies->display_price( $f['products_price'], tep_get_tax_rate( $f['products_tax_class_id'] ) ) . "',";
if ( tep_not_null($f['specials_new_products_price']) )
$random_products_script .= "'" . $currencies->display_price( $f['specials_new_products_price'], tep_get_tax_rate( $f['products_tax_class_id'] ) ) . "',";
else
$random_products_script .= "'',\n";
$random_products_script .= "false";
$random_products_script .= ") );\n";
}
$random_products_script .= 'loadRandomProduct();' . "\n";
$random_products_script .= '</script>' . "\n";
?>
<!-- random_products //-->
<tr>
<td>
<?php
$info_box_contents = array();
$info_box_contents[] = array('text' => BOX_HEADING_RANDOM_PRODUCTS);
new infoBoxHeading($info_box_contents, false, false);
$info_box_contents = array();
$info_box_contents[] = array('align' => 'center',
'text' => '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="' . (SMALL_IMAGE_HEIGHT+30) . '" class="infoBoxContents"><tr><td align="center"><div id="randomProductDiv"></div></tr></td></table>' . $random_products_script );
new infoBox($info_box_contents);
?>
<table border="0" cellspacing="0" cellpadding="0" width="125">
<tr>
<td align="center"><img src="images/footer1.gif"></td>
</tr>
</table>
</td>
</tr>
<!-- random_products_eof //-->
<?php
}
?>
I have posted it on the oscommerce forums but no-one seems to answer posts there (or maybe its just my posts that don't get answered) ;(
Thanks for your reply tho' - I'll keep searching.
Sorry again about the code