rnt Posted July 11, 2003 Share Posted July 11, 2003 Help Please.. This code is from Display Products contribution. How can i change the code for random products only fro one categorie?? Thks for the time.. Renato Duarte $product_info = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, .products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, .products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . ABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and .products_id = '" . $HTTP_GET_VARS['products_id'] . "'and .language_id = '" . $languages_id . "'"); $new_products_query = tep_db_query("select substring pd.products_description, 1, 200) as products_description, p.products_id, .products_image, p.manufacturers_id, .products_tax_class_id from " . ABLE_PRODUCTS . " , " . TABLE_PRODUCTS_DESCRIPTION . " pd where .products_id = pd.products_id and p.products_status = '1' and pd.products_description != '' order by rand() DESC limit " .'5'); $new_products = tep_db_fetch_array($new_products_query); $new_products['products_name'] = tep_get_products_name $new_products['products_id']); :huh: :huh: Link to comment Share on other sites More sharing options...
Guest Posted July 11, 2003 Share Posted July 11, 2003 something like this should do the trick $new_products_query =tep_db_query("select select substring pd.products_description, 1, 200) as products_description, p.products_id, .products_image, p.manufacturers_id, .products_tax_class_id from from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "' ) order by rand() DESC limit " .'5'"); Link to comment Share on other sites More sharing options...
rnt Posted July 11, 2003 Author Share Posted July 11, 2003 First of all, thks for the help.. I replace your code but I get.. Parse error: parse error in /var/www/html/loja/includes/boxes/display_product.php on line 18 I tried to fix but, i really don?t much of php code.. :roll: :roll: Link to comment Share on other sites More sharing options...
Guest Posted July 11, 2003 Share Posted July 11, 2003 $current_category_id . "' ) order by rand() DESC limit " .'5'"); should not have the last ", try: $current_category_id . "' ) order by rand() DESC limit " .'5'); Hth, Matt Link to comment Share on other sites More sharing options...
rnt Posted July 11, 2003 Author Share Posted July 11, 2003 Well, not very nice :cry: 1064 - You have an error in your SQL syntax near 'select substring pd.products_description, 1, 200) as products_description, p.pr' at line 1 select select substring pd.products_description, 1, 200) as products_description, p.products_id, .products_image, p.manufacturers_id, .products_tax_class_id from from products p, products_description pd, products_to_categories p2c, categories c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '4' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '0' OR c.parent_id = '0' ) order by rand() DESC limit 5 Link to comment Share on other sites More sharing options...
Guest Posted July 11, 2003 Share Posted July 11, 2003 Take out the first select in select select. Good luck, Matt Link to comment Share on other sites More sharing options...
rnt Posted July 11, 2003 Author Share Posted July 11, 2003 Still have the same problem.. but without the first "select" :? Link to comment Share on other sites More sharing options...
Guest Posted July 11, 2003 Share Posted July 11, 2003 The first letter of a couple lines got lost, try this: "select substring (pd.products_description, 1, 200) as products_description, p.products_id, p.products_image, p.manufacturers_id, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "' ) order by rand() DESC limit 5" Good luck, Matt Link to comment Share on other sites More sharing options...
rnt Posted July 11, 2003 Author Share Posted July 11, 2003 thks, but i still have the same error.. :cry: 1064 - You have an error in your SQL syntax near '(pd.products_description, 1, 200) as products_description, p.products_id, p.pro' at line 1 select substring (pd.products_description, 1, 200) as products_description, p.products_id, p.products_image, p.manufacturers_id, p.products_tax_class_id from products p, products_description pd, products_to_categories p2c, categories c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '4' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '0' OR c.parent_id = '0' ) order by rand() DESC limit 5 Link to comment Share on other sites More sharing options...
Guest Posted July 11, 2003 Share Posted July 11, 2003 "select substring(pd.products_description, 1, 200) as products_description, p.products_id, p.products_image, p.manufacturers_id, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "' ) order by rand() DESC limit 5" Maybe it didn't like the space between substring and (. Good luck, Matt Link to comment Share on other sites More sharing options...
rnt Posted July 12, 2003 Author Share Posted July 12, 2003 It works fine.. thks.. :D Just one question.. Where do i put the number of the categirie, that i want to ramdom products? It?s the last one. thks again... <? $product_info = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and pd.products_id = '" . $HTTP_GET_VARS['products_id'] . "'and pd.language_id = '" . $languages_id . "'"); $new_products_query = tep_db_query ("select substring(pd.products_description, 1, 200) as products_description, p.products_id, p.products_image, p.manufacturers_id, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "' ) order by rand() DESC limit 5"); $new_products = tep_db_fetch_array($new_products_query); $new_products['products_name'] = tep_get_products_name($new_products['products_id']); ?> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="0" > <tr> <td> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center"><div align="center"> <center> <table border="0" width="100%" cellpadding="0" cellspacing="0" > <tr> <td class="main"> <? echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a>';?></td> <td align="right"><table border="0" cellpadding="0" cellspacing="0"> <tr> <td><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], 'Computadores', 185, 150) . '</a>'; ?></td> </tr> </table> </td> </tr> </table> </center> </div> </td> </tr> <tr> <td class="main"> <?echo $new_products['products_description']?>...<a href="<?echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']);?>">Read More</a></td> </tr></table> </center> </div> </td> </tr> </table> </td> </tr> </table> </center> </div> Link to comment Share on other sites More sharing options...
rnt Posted July 12, 2003 Author Share Posted July 12, 2003 :D :D :D :D :D :D :D After a few tests i have done it ... Thks again.. :D :D :D :D :D Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.