Skip to main content
JBWebWorks
Inspiring
May 19, 2009
Question

How to nest a recordset inside a repeat region php/mysql?

  • May 19, 2009
  • 1 reply
  • 1195 views

I have a products page with a recordset listing items by category.

i have a 2nd recordset on the same page with color choices for each item

sql for color recordset-

mysql_select_db($database_connstore, $connstore); $query_rs_colors = "SELECT * FROM color_lookup, colors, items WHERE color_lookup.item_colorID = items.item_colorID"; $rs_colors = mysql_query($query_rs_colors, $connstore) or die(mysql_error()); $row_rs_colors = mysql_fetch_assoc($rs_colors); $totalRows_rs_colors = mysql_num_rows($rs_colors);

table color_lookup has two columns, color_ID and item_colorID, joint primary keys

table colors has two colums, color_ID and colors, color_ID is primary and auto increment (nine different colors)

table items has numerous colums, one being item_colorID, which is an index

i have the items recordset with a repeat region.

i put a dreamweaver menu inside the repeat region and populated dynamically with the color recordset.

When viewed in a browser, the items list properly but the menu shows incorrectly.

I have been told that for the list to match the item, i have to nest the recordset code inside the repeat region. I am not sure where and what code to move?

thanks for any help,

jim balthrop

ps-this is a continuation from a previous thread, but i felt it has changed so much, that i needed to start over.

This topic has been closed for replies.

1 reply

JBWebWorks
Inspiring
May 19, 2009

I got the answer now.

The second recordset, colors, since it is nested inside the repeat region, had to have a variable and PHP code also inside the repeat region to set the variable.

the sql for the colors recordset

SELECT * FROM colors INNER JOIN color_lookup ON color_lookup.color_ID = colors.color_ID WHERE color_lookup.item_colorID = myfakevar

the runtime value of the variable, myfakevar is $_POST['myfakevar']

The PHP code to set the variable to filter by the item id of the items recordset

<?php

$_POST['myfakevar'] = $row_rs_itemscat3['item_colorID'];

?>

here is the page (not finished yet, but you can see the color menu)

http://www.farrington-enterprises.com/rain-gutters.php

JBWebWorks
Inspiring
May 21, 2009

Thanks for your help

jim balthrop