kstapleton Posted July 27, 2010 Share Posted July 27, 2010 Hi guys, I'm new to PHP, have some other coding experience. But I'm having a problem with duplicate results from my query. $result = tep_db_query(" SELECT pd.products_id, pd.products_name, p.products_image, p.products_status FROM products_description pd LEFT OUTER JOIN products p ON p.products_id = pd.products_id WHERE pd.products_id IN (SELECT products_id FROM products_to_categories WHERE categories_id = ".$catid." ) AND p.products_status = 1 AND pd.language_id = '" . (int)$languages_id . "' ORDER BY pd.products_name ") while($row = tep_db_fetch_array( $result )) { $output .= '<li><a href="product_info.php?products_id='.$row["products_id"].'">'.$row['products_name'].'</a></li>'; echo $output; } So I will end up getting product 1 product 2 product 1 product 1 product 3 and so on... If I run the query in my DB admin, it returns the results correctly with no duplicates. I'm nto sure what is adding the duplicates. If it's "tep_db_query" or "tep_db_fetch_array" or something else. Thank you for your time and help!! Link to comment Share on other sites More sharing options...
chadcloman Posted July 27, 2010 Share Posted July 27, 2010 You are appending to $output but echoing it within the loop. So you'll get something like this: 1 1 2 1 2 3 1 2 3 4 You need to either place the echo statement outside the while loop, or change $output .= '<li><a href="product_info.php?products_id='.$row["products_id"].'">'.$row['products_name'].'</a></li>'; such that it uses "=" instead of ".=". Here's what I suggest for the while loop: while($row = tep_db_fetch_array( $result )) { echo '<li><a href="product_info.php?products_id='.$row["products_id"].'">'.$row['products_name'].'</a></li>'; } Check out Chad's News. Link to comment Share on other sites More sharing options...
satish Posted September 18, 2010 Share Posted September 18, 2010 Hi guys, I'm new to PHP, have some other coding experience. But I'm having a problem with duplicate results from my query. $result = tep_db_query(" SELECT pd.products_id, pd.products_name, p.products_image, p.products_status FROM products_description pd LEFT OUTER JOIN products p ON p.products_id = pd.products_id WHERE pd.products_id IN (SELECT products_id FROM products_to_categories WHERE categories_id = ".$catid." ) AND p.products_status = 1 AND pd.language_id = '" . (int)$languages_id . "' ORDER BY pd.products_name ") while($row = tep_db_fetch_array( $result )) { $output .= '<li><a href="product_info.php?products_id='.$row["products_id"].'">'.$row['products_name'].'</a></li>'; echo $output; } So I will end up getting product 1 product 2 product 1 product 1 product 3 and so on... If I run the query in my DB admin, it returns the results correctly with no duplicates. I'm nto sure what is adding the duplicates. If it's "tep_db_query" or "tep_db_fetch_array" or something else. Thank you for your time and help!! There is no problem in query also not in fetch array Only problem with echo (data). Replace code $output .= '<li><a href="product_info.php?products_id='.$row["products_id"].'">'.$row['products_name'].'</a></li>'; echo $output; with this echo '<li><a href="product_info.php?products_id='.$row["products_id"].'">'.$row['products_name'].'</a></li>'; Satish Ask/Skype for Free osCommerce value addon/SEO suggestion tips for your site. Check My About US For who am I and what My company does. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.