How can I assign products to other products? Totally Stuck!!
Posted: Wed Oct 19, 2011 6:29 am
Here's a very difficult problem that I hope someone can see a way around, as I am stuck.
We sell products, and accessories/parts for the products.
So what we have is an EDIT page in Admin where you can go into, for example, a Battery Pack.
You then assign products to that battery pack. Could be 1 product, could be 5 (or more).
You then go to the Accessories page and see all products *that have been assigned to accessories*.
Obviously you only want to show these products once. So you might click on "Ford Truck", and it would display gearknob, wipers, steering wheel..... for example.
The problem is, I am doing this with tokens. So the "productassign" field for each accessory might show like this:
[text]gearknob|wipers|steering wheel[/text]
Previously we only wanted to have ONE product assigned to any accessories, so I just used the DISTINCT term so it dragged out ONE product, whether 5 were assigned to it or not. As the field only had one item in it.
But with multiples, I cannot do this.
The code I have done so far is below, but it's messed up. How can I achieve this effect?
We sell products, and accessories/parts for the products.
So what we have is an EDIT page in Admin where you can go into, for example, a Battery Pack.
You then assign products to that battery pack. Could be 1 product, could be 5 (or more).
You then go to the Accessories page and see all products *that have been assigned to accessories*.
Obviously you only want to show these products once. So you might click on "Ford Truck", and it would display gearknob, wipers, steering wheel..... for example.
The problem is, I am doing this with tokens. So the "productassign" field for each accessory might show like this:
[text]gearknob|wipers|steering wheel[/text]
Previously we only wanted to have ONE product assigned to any accessories, so I just used the DISTINCT term so it dragged out ONE product, whether 5 were assigned to it or not. As the field only had one item in it.
But with multiples, I cannot do this.
The code I have done so far is below, but it's messed up. How can I achieve this effect?
Code: Select all
$result = mysql_query ("SELECT productassign FROM products WHERE (productassign IS NOT NULL OR productassign != '') ORDER BY title");
if (mysql_num_rows($result)==0) { echo "We are building our parts pages right now - they will be available soon.<br/>
You will be able to find your own product, and view their related parts here.";}
while ($row = mysql_fetch_object($result))
{
$string = "$row->productassign";
$token = strtok($string,"|");
while($token)
{
$result2 = mysql_query ("SELECT title, price, photoprimary, id FROM products WHERE title = '$token'");
while ($row2 = mysql_fetch_object($result2))
{
echo "<div class='cat_prodlistbox' style='height: 185px'><a href='index.php?page=productaccs&menu=home&id=$row2->id&title=$row2->title' title='Look at the $row2->title' style='text-decoration: none'>";
if ($row2->photoprimary == NULL) { echo "<img src='images/blank.gif' border='0' />";}
elseif ($row2->photoprimary != NULL) { echo"
<img src='images/productphotos/small/$row2->photoprimary' border='0' style='border: 1px solid #000000'/><img src='images/imageshadow.png' border='0' class='shadowmedium'/><br/>";}
echo "$row2->title<br/>£";
printf ("%.2f", $row2->price);
echo "</a></div>";
}
} mysql_free_result($result2);
} mysql_free_result($result);