ecommerce website ASP coded using MS SQL:

product page - display product with all atributes.
|----> on product page display associated products.
|
|----> Optional products are pulled from the database via a table with two columns, one column for each linked product.

So on the product page it looks at this table to see if any products are associated with it and displays it.


In the shopping cart, it does the same thing, it displays the associated prdocuts. If there is more than one product in the shopping cart, I set the first loop to loop through the products in the cart (one table in the DB), and within that loop I loop again to pull each associated product (from the associated product table in the DB).

My issue is: Some products in the shopping cart will end up have the same associated products and end up displaying the same associated product, in other words the same item will be shown more than once. How do I limit the script to only display an associated product once?

Depends on how your database is set up, but you could add "DISTINCT" to your SQL query. By this, it only grabs unique names.

"SELECT DISTINCT productname FROM blablah"


Otherwise, you should do a grab on both tables at once, then loop through and put into two columns.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.