Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need help with PHP coding


reddragonsa

Recommended Posts

Posted

Hi

 

I have modified the index.php and new_products.php. But am having a problem with the way the products are displayed. I want the products sorted by category and not by date added.

 

The code is:

<?php

$info_box_contents = array();

$info_box_contents[] = array('text' => TABLE_HEADING_OUR_PRODUCTS);

 

new infoBoxHeading($info_box_contents, false, false) ;

 

 

 

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, pc.categories_id, p left join " . TABLE_PRODUCTS_TO_CATEGORIES . " pc on p.products_id = pc.products_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by pc.categories_id desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

 

 

 

$row = 0;

$col = 0;

$info_box_contents = array();

while ($new_products = tep_db_fetch_array($new_products_query)) {

$info_box_contents[$row][$col] = array('align' => 'center',

'params' => 'class="smallText" width="33%" valign="top"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])));

 

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

 

new contentBox($info_box_contents);

 

?>

 

I get the following error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'left join products_to_categories pc on p.products_id = pc.products_id, if(s.stat' at line 1

 

select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, pc.categories_id, p left join products_to_categories pc on p.products_id = pc.products_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from products p left join specials s on p.products_id = s.products_id, products_description pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' order by pc.categories_id desc limit 25

 

ThanX

Red

Posted

Try changing this

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, pc.categories_id, p left join

to

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, pc.categories_id from

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Posted
Try changing this
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, pc.categories_id, p left join

to

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, pc.categories_id from

 

Jack

 

 

hi Jack... thanx, but it still down sot work.

 

cheers

Red

Posted
hi Jack... thanx, but it still down sot work.

 

cheers

Red

 

I'm really not sure what that query was trying to achieve because it isn't going to work, try the following and make adjustments where necessary. This works in strict mode so should work wherever.

 

Remember though that I am guessing the required output. Also note that specials price will come out as final_price to seperate itself from products_price.

 

$new_products_query = tep_db_query("

SELECT p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, p2c.categories_id,

IF( s.status, s.specials_new_products_price, p.products_price ) AS final_price

FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_PRODUCTS_DESCRIPTION . " pd

LEFT JOIN " . TABLE_SPECIALS . " s ON pd.products_id = s.products_id

WHERE p.products_id = pd.products_id

AND p.products_id = p2c.products_id

AND p.products_status = '1'

AND pd.language_id = '" . (int)$languages_id . "'

ORDER BY p2c.categories_id, pd.products_name DESC

LIMIT " . MAX_DISPLAY_NEW_PRODUCTS);

Posted
I'm really not sure what that query was trying to achieve because it isn't going to work, try the following and make adjustments where necessary. This works in strict mode so should work wherever.

 

Remember though that I am guessing the required output. Also note that specials price will come out as final_price to seperate itself from products_price.

 

$new_products_query = tep_db_query("

SELECT p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, p2c.categories_id,

IF( s.status, s.specials_new_products_price, p.products_price ) AS final_price

FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_PRODUCTS_DESCRIPTION . " pd

LEFT JOIN " . TABLE_SPECIALS . " s ON pd.products_id = s.products_id

WHERE p.products_id = pd.products_id

AND p.products_id = p2c.products_id

AND p.products_status = '1'

AND pd.language_id = '" . (int)$languages_id . "'

ORDER BY p2c.categories_id, pd.products_name DESC

LIMIT " . MAX_DISPLAY_NEW_PRODUCTS);

 

Hi

Thank you so much!!!!!

 

Cheers

RED

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...