Forum Moderators: coopster

Message Too Old, No Replies

Is there something wrong with this php code?

         

Fallen Angel

11:49 am on Mar 14, 2008 (gmt 0)

10+ Year Member



Hi,
I have copied an oscommerce contribution and all works well (ish!) but I think that the products name should be in the box and it isn't showing. Also, the box for some reason isn't using my stylesheet properly as the text looks different.
Please could anyone help? Go easy on me please, I'm very new to this.
Many thanks in advance.
<?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
}
?>

Habtom

5:29 am on Mar 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is some pretty heavy code :)

It would be easier for you to get a response on the oscommerce forums as this is more of a specific product related question. If not, you might need to point out, the specifics and avoid dumping a huge code to get a quick support.

Fallen Angel

11:07 am on Mar 16, 2008 (gmt 0)

10+ Year Member



Sorry about that, am still really new to this and don't know which bits are relevant and which bits are not. I have brought lots of books though :0)

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

jatar_k

1:28 pm on Mar 16, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what "box" do you mean

is it a textbox or just a visual box somewhere on the page?

is it this var we might be looking at?
$info_box_contents

do you know what function returns the product name?
What data shows up in there now?

most of that code seems to just be writing out javascript for the page

Fallen Angel

2:26 pm on Mar 16, 2008 (gmt 0)

10+ Year Member



Hi,
Thank you for responding.
It's ok, I have just removed the box from my site as it was making my page load very slowly. I hadn't realised that this was the cause of that.

Many thanks for trying to help though, it's much appreciated.