Forum Moderators: coopster

Message Too Old, No Replies

Showing pictures of different colors of the "same" product

         

Joppiesaus

1:08 pm on Oct 24, 2008 (gmt 0)

10+ Year Member



Hello,

In a webshop which im working on there is the possibility that one product is available in different colors. These products have to be inserted sepreately beacuse they have different EAN codes and are basically different products.

However, for the visitor it might be interesting to show pictures of these similar products with different colors. I already created a field called "groupnumber" where the same number is filled in for every color of the same product type.

I dont know however how to create (a new recordset?) a way to show the images of these products.

variables used in the database:
- id --> unique numbe which is also the "image name". So an image is loaded like this: /images/<?php echo $row_Recordset1['id']; ?>.jpg
- groupnumber

All products are stored in the same table called "product".

Please let me know what you think would be the best way.

Kind regards,

Nick.

cameraman

4:56 pm on Oct 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you retrieve a product's record, look to see if it's in a group. If it is, then retrieve the other pictures by groupnumber:
SELECT id WHERE groupnumber=$variable_with_the_group_number

Joppiesaus

10:33 pm on Oct 24, 2008 (gmt 0)

10+ Year Member



Ok, this is probably exactly what I'm looking for, but how do I write the SQL code? Normally I use the Recordset generator from Dreamweaver, but this is too tricky for the configurator. If you could post the exact code I should use I could probably manage to fill in my own table name (product) and the variables needed (id and groupnumber).

($variable_with_the_group_number --> this isnt how it should be inserted right?)

Thanks.

cameraman

12:43 am on Oct 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's going to be something like:
if($row_Recordset1['groupnumber']) {
$query = mysql_query("SELECT id FROM product WHERE groupnumber={$row_Recordset1['groupnumber']}");
if(mysql_num_rows($query)) {
while($rec = mysql_fetch_row($query))
echo "<img src=\"/images/{$rec[0]}.jpg\">";
} // EndIf other members in gruop
} // EndIf is member of a group

Look at the library topics I linked to in your other thread, especially the one on extracting data from mysql.

Joppiesaus

11:09 am on Oct 27, 2008 (gmt 0)

10+ Year Member



Thanks, it works now!

Code:
<?php if($row_Recordset1['groepnummer']) {
$query = mysql_query("SELECT id, naam, categorie, subcategorie, slug FROM product WHERE groepnummer={$row_Recordset1['groepnummer']}");
if(mysql_num_rows($query)) {
while($rec = mysql_fetch_row($query))
echo "<a href='/".str_replace(array('%20', ' '), '-', $rec[2]) ."/".str_replace(array('%20', ' '), '-', $rec[3]) ."/".str_replace(array('%20', ' '), '-', $rec[4]) ."/'><img src=\"/images/thumb/{$rec[0]}.jpg\" height='40' width='40' border='0' alt='".$rec[2]." &raquo; ".$rec[1]."'></a>&nbsp;";
}
}
?>