Skip to main content
Participating Frequently
January 17, 2011
Answered

Show related products in Dreamweaver

  • January 17, 2011
  • 1 reply
  • 2442 views

hi all i'm pretty new to all this so forgive me! I'm doing a website for my brother that will sell guitar bodies and their relevant parts. I've setup a single mysql database table - one of the fields determines if the entry is a body or a part - there is also a field in which (if it's a part) the relevant body its linked to is entered. So, part54 maybe related to body1 for example. I've setup a page in DW CS5 that correctly shows bodies, i've then created a second recordset which i'm trying to filter by the current record in the first recordset. So, if the user is viewing item number 1 then any parts related to that product can be listed on the same page (and eventually clicked for more info). I'm really struggling to find out how to reference the current record being displayed in the first recordset from within the second. Please can you advise me? So, in English Recordset2 needs to show all records where the relateditemfield = the currently being displayed record. I hope i've given enough info here, please shout if not. Thanks in advance. John.

This topic has been closed for replies.
Correct answer

OK - almost there and you've taught me loads, thank you. The Repeat Region code was much further down but I've now made lines 67 to 71 ..

.$xxxxxx = $row_Recordset1['itemid'];

?>
<?php

which took away the syntax error.

Now, the repeat region is working, everything is working - but - at the top of the page when I look in browser it now suddenly says ...

$queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?>


Take the information from my last post and reverse the logic... The reason the php code is displaying on your page and not processed by the server is because you do not have an opening tag.

1 reply

January 17, 2011

Do some research on MySQL JOIN or create first recordset and get value of row then in second recordset use WHERE argument to filter data WHERE table_column = row_first_recordset['value']

Participating Frequently
January 18, 2011

Thank you. I looked up JOIN and think that would be more suited if I was using two tables, but in this case all products are stored in one table.

Your second idea is the one I've been trying to work on. Would you mind giving me some guidance how it should look?

I've tried ...

SELECT *
FROM bodies
WHERE relateditems = row_first_recordset1['itemid']

but no luck. The itemid is showing on the page from recordset1, I need to use this value as the filter for recordset2.

Thanks so much.

John

Participating Frequently
January 18, 2011

You still need to use a join. Your table has a "fishhook" type relation with itself. That is, each row in the table references another row in the table. You need to create an alias to the table for the related products:

SELECT a.column1, a.column2, b.column1, b.column2, etc.
FROM bodies a, bodies b
WHERE a.product_id = b.relateditems

AND ....   (whatever other criteria you need)