Answered
Problem with my innerjoin. please help
Hello;
I am trying to write kind of a complicated page and I am getting an error in my query. I do have another question for this query that I can't get to work, but lets do this one problem at a time.
This is the error I get when going directly to this page:
Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Projects.CategoryID Categories.Name'.
The error occurred on line 12.
This is my code:
<!--- This is the query with the error, It runs the project records and either brings them all up or just those in the category chosen from another page. --->
<cflock timeout="10" type="exclusive" scope="application">
<cfquery name="getProjects" datasource="#APPLICATION.dataSource#">
SELECT Projects.Name AS PName, Projects.ProjectID AS ID, Projects.CategoryID
Categories.Name AS CName, Categories.CategoryID
FROM Projects INNER JOIN Categories ON projects.CategoryID = Categories.CategoryID
<cfif StructKeyExists(url, 'CategoryID')>
WHERE Categories.CategoryID = <cfqueryparam CFSQLType="CF_SQL_INTEGER" value="#URL.CategoryID#" />
AND Categories.CategoryID = Projects.CategoryID
ORDER BY Projects.Name
<cfelse>
ORDER BY Categories.Name
</cfif>
</cfquery>
<cfset rowsPerPage = 6>
<cfparam name="URL.startRow" default="1" type="numeric">
<cfset totalRows = getProjects.recordCount>
<cfset endRow = min(URL.startRow + rowsPerPage - 1, totalRows)>
<cfset startRowNext = endRow + 1>
<cfset startRowBack = URL.startRow - rowsPerPage>
</cflock>
<!--- End project file code --->
<!--- This code runs the success in updating your #record# --->
<cfif isDefined("URL.ID")>
<cfquery name="zlnbbXX" datasource="#APPLICATION.dataSource#" maxrows="1">
SELECT Projects.Name AS PName, Projects.ProjectID AS ID, Projects.CategoryID
WHERE ProjectID = #URL.ID#
</cfquery>
</cfif>
<!--- end code--->
<head>
</head>
<body>
<!--- code for Success update record --->
<cfif isDefined("URL.RecordID")>
<cfoutput query="zlnbbXX">
<font color="##990000" face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Updates Have Successfully Been Applied to:</b><br><u>#PName#</u></font><br></cfoutput></cfif>
<!--- end success --->
<!-- records and next / prev nav --->
<cfoutput>
Displaying <b>#URL.startRow#</b> to <b>#endRow#</b> of <b>#totalRows#</b> Records</font>
<cfset urlVars = "">
<cfif startRowBack GT 0>
<cfset urlVars = "startRow=#startRowBack#">
</cfif>
<cfif structKeyExists(url, 'categoryID')>
<cfset urlVars = urlVars & "categoryID=#categoryID#">
</cfif>
<a href="#CGI.script_name#?#urlVars#" class="nav">< Previous Records</a>
<cfset urlVars = "" >
<cfif startRowNext lte totalRows>
<cfset urlVars = "startRow=#startRowNext#">
</cfif>
<cfif structKeyExists(url, 'categoryID')>
<cfset urlVars = urlVars & "categoryID=#categoryID#">
</cfif>
<a href="#CGI.script_name#?#urlVars#" class="nav">Next ></a>
</cfoutput>
<!--- end next / prev code --->
<!-- records to edit --->
<cfloop query="getProjects" startRow="#URL.startRow#" endrow="#endRow#"><cfset class = iif(getProjects.currentRow mod 2 eq 0, " 'DataA' ", " 'DataB' ")>
<cfoutput>
#PName#
#CName#
<form name="myform" action="Action.cfm" method="post">
<input type="hidden" name="ID" value="#ID#">
<input type="submit" ... More code here>
</cfoutput>
</cfloop>
This query does a few things.
1. if you go to this page directly, it shows all the projects title so you can next / prev through the records and edit the record you want.
2. I am trying to make it so that if you come from another page that edits all the categories for this section, it will only bring up the projects under that category. It did that, but when you next / prev through it, it brings up all the records.
3. After you add or update a record, when you are sent back to this page, it tells you, "Your updates were successful for #title of project#"
I commented out the code, I know there is a couple issues here and I need help figuring them out.
CFmonger
I am trying to write kind of a complicated page and I am getting an error in my query. I do have another question for this query that I can't get to work, but lets do this one problem at a time.
This is the error I get when going directly to this page:
Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Projects.CategoryID Categories.Name'.
The error occurred on line 12.
This is my code:
<!--- This is the query with the error, It runs the project records and either brings them all up or just those in the category chosen from another page. --->
<cflock timeout="10" type="exclusive" scope="application">
<cfquery name="getProjects" datasource="#APPLICATION.dataSource#">
SELECT Projects.Name AS PName, Projects.ProjectID AS ID, Projects.CategoryID
Categories.Name AS CName, Categories.CategoryID
FROM Projects INNER JOIN Categories ON projects.CategoryID = Categories.CategoryID
<cfif StructKeyExists(url, 'CategoryID')>
WHERE Categories.CategoryID = <cfqueryparam CFSQLType="CF_SQL_INTEGER" value="#URL.CategoryID#" />
AND Categories.CategoryID = Projects.CategoryID
ORDER BY Projects.Name
<cfelse>
ORDER BY Categories.Name
</cfif>
</cfquery>
<cfset rowsPerPage = 6>
<cfparam name="URL.startRow" default="1" type="numeric">
<cfset totalRows = getProjects.recordCount>
<cfset endRow = min(URL.startRow + rowsPerPage - 1, totalRows)>
<cfset startRowNext = endRow + 1>
<cfset startRowBack = URL.startRow - rowsPerPage>
</cflock>
<!--- End project file code --->
<!--- This code runs the success in updating your #record# --->
<cfif isDefined("URL.ID")>
<cfquery name="zlnbbXX" datasource="#APPLICATION.dataSource#" maxrows="1">
SELECT Projects.Name AS PName, Projects.ProjectID AS ID, Projects.CategoryID
WHERE ProjectID = #URL.ID#
</cfquery>
</cfif>
<!--- end code--->
<head>
</head>
<body>
<!--- code for Success update record --->
<cfif isDefined("URL.RecordID")>
<cfoutput query="zlnbbXX">
<font color="##990000" face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Updates Have Successfully Been Applied to:</b><br><u>#PName#</u></font><br></cfoutput></cfif>
<!--- end success --->
<!-- records and next / prev nav --->
<cfoutput>
Displaying <b>#URL.startRow#</b> to <b>#endRow#</b> of <b>#totalRows#</b> Records</font>
<cfset urlVars = "">
<cfif startRowBack GT 0>
<cfset urlVars = "startRow=#startRowBack#">
</cfif>
<cfif structKeyExists(url, 'categoryID')>
<cfset urlVars = urlVars & "categoryID=#categoryID#">
</cfif>
<a href="#CGI.script_name#?#urlVars#" class="nav">< Previous Records</a>
<cfset urlVars = "" >
<cfif startRowNext lte totalRows>
<cfset urlVars = "startRow=#startRowNext#">
</cfif>
<cfif structKeyExists(url, 'categoryID')>
<cfset urlVars = urlVars & "categoryID=#categoryID#">
</cfif>
<a href="#CGI.script_name#?#urlVars#" class="nav">Next ></a>
</cfoutput>
<!--- end next / prev code --->
<!-- records to edit --->
<cfloop query="getProjects" startRow="#URL.startRow#" endrow="#endRow#"><cfset class = iif(getProjects.currentRow mod 2 eq 0, " 'DataA' ", " 'DataB' ")>
<cfoutput>
#PName#
#CName#
<form name="myform" action="Action.cfm" method="post">
<input type="hidden" name="ID" value="#ID#">
<input type="submit" ... More code here>
</cfoutput>
</cfloop>
This query does a few things.
1. if you go to this page directly, it shows all the projects title so you can next / prev through the records and edit the record you want.
2. I am trying to make it so that if you come from another page that edits all the categories for this section, it will only bring up the projects under that category. It did that, but when you next / prev through it, it brings up all the records.
3. After you add or update a record, when you are sent back to this page, it tells you, "Your updates were successful for #title of project#"
I commented out the code, I know there is a couple issues here and I need help figuring them out.
CFmonger
