Advertisement

03.25.2008 at 05:50AM PDT, ID: 23266742
[x]
Attachment Details

nested query loop  not working properly

Asked by xoundboy in Web Languages/Standards, Cold Fusion Markup Language

I have been trying to solve this for hours now but have really lost the plot. Maybe someone can help me. Here's a simplified version of the problem:

there are two MySQL tables - "menu" and "pages" (see sql below)

One page can be assigned to each menu item.

Now I would like to display a table where each row represents one menu item and there is a column where you can select from a drop-down box which page is assigned to each menu item.

so far so good.

I have written a template to display such a page. The problem is that the select box does not display the currently assigned page correctly. For some strange and unknown reason it all of the rows show the same assignment, even though they are assigned differently.

any ideas why?


Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
Here's the SQL...
 
CREATE TABLE `menu` (
  `menuID` smallint(4) NOT NULL auto_increment,
  `menuItem` varchar(64) collate latin1_general_ci default NULL,
  `pageID` smallint(4) default NULL,
  PRIMARY KEY  (`menuID`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
INSERT INTO `menu` VALUES ('1', 'Blog', '1');
INSERT INTO `menu` VALUES ('2', 'Photos', '2');
INSERT INTO `menu` VALUES ('3', 'News', '3');
INSERT INTO `menu` VALUES ('4', 'Projects', '4');
 
CREATE TABLE `pages` (
  `pageID` smallint(4) NOT NULL auto_increment,
  `pagename` varchar(64) collate latin1_general_ci default NULL,
  PRIMARY KEY  (`pageID`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
INSERT INTO `pages` VALUES ('1', 'Blog');
INSERT INTO `pages` VALUES ('2', 'photos');
INSERT INTO `pages` VALUES ('3', 'News');
INSERT INTO `pages` VALUES ('4', 'Projects');
 
 
Now, here's the code..
 
 
<cfquery name="getPages" datasource="#APPLICATION.datasource#">
	SELECT *
    FROM pages
</cfquery>
 
<cfquery name="getMenu" datasource="#APPLICATION.datasource#">
	SELECT *
    FROM	menu
</cfquery>
 
<cfform action="">
    <table width="400" border="1px">
        <tr>
            <th>menu item</th>
            <th>menu ID</th>
            <th>pageID</th>
            <th>pagename</th>
        </tr>
        
        <!--- output menu item as table row --->
        <cfoutput query="getMenu">
            <tr>
                <td>#menuItem#</td>
                <td>#menuID#</td>
                <td>#pageID#</td>
                <td>
                	<cfselect name="pageID_#getMenu.menuID#">
                        <cfloop query="getPages">
                        	<option value="#getPages.pageID#"
                            	<cfif #getPages.pageID# eq #getMenu.pageID#>
                                	selected="selected"
                                </cfif>>#pagename#
                            </option>
                        </cfloop>
                    </cfselect>
                </td>
            </tr>
        </cfoutput>
    </table>
</cfform>
 
Loading Advertisement...
 
[+][-]03.25.2008 at 10:27AM PDT, ID: 21204028

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.25.2008 at 11:31AM PDT, ID: 21204646

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.25.2008 at 06:11PM PDT, ID: 21207992

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Web Languages/Standards, Cold Fusion Markup Language
Sign Up Now!
Solution Provided By: danrosenthal
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03.26.2008 at 03:06AM PDT, ID: 21210071

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.26.2008 at 08:50AM PDT, ID: 21212935

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628