Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6860771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:27:01+00:00 2026-05-27T02:27:01+00:00

When inserting products in an eshop we often need to link some products (aka

  • 0

When inserting products in an eshop we often need to link some products (aka related products) to others and the linking must be done both ways, meaning if I link product1 to product2 then product2 must also be linked to product1.

Which is the best practice, using an extra table ‘relations’ (prodid, related_prodid) or to keep a list of related products in a delimited string in each product’s row in the products table?

In either case, we would also need a recursive method to loop through a given array of products and insert/update the tables with the relations, could someone help me out with the algorithm? I will do the PHP coding but I cant think of a good way to do it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:27:02+00:00Added an answer on May 27, 2026 at 2:27 am

    You’d better use an intermediate table related_to(id, product1, product2)

    Then, you’ll use the code:

    function findRelatedProducts($product) {
      $relatedProducts = array();
      $data = mysql_query("SELECT * FROM related_to WHERE product1='$product' OR product2='$product'");
      while ($relation = mysql_fetch_array($data)) {
        $relatedProducts[] = $relation['product1'] == $product ? $relation['product2'] : $relation['product1'];
      }
      return $relatedProducts;
    }
    

    Of course, you need to JOIN this table with your product table, but since I don’t have much informations about your mysql structure, I’ll let you check on this site if you don’t know how.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After inserting new html to DOM,I need to add some listeners to it. But
When inserting a row in mysql database, string values need to be enclosed in
I have a question, I have a database with some webshop products. I load
I have only done databases without relations, but now I need to do something
I'm adding some products though to a magento store front through the soap API
I have a question about inserting row order number by spesific order type. Products
Inserting rows one by one from a 600 record data-set is taking almost an
When inserting copy into an HTML document I get from sources such as word
I'm inserting multiple records into a table A from another table B. Is there
I am inserting a column in a DataGridView programmatically (i.e., not bound to any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.