Solved

<cfquery name  <cfif

Posted on 2013-01-04
10
454 Views
Last Modified: 2013-01-04
Hello,

I have this Data into my SQL Table TblDataInfo.

Example of my data:

Data_ID:                 10254
user_submitted:            1
user_date_submitted:      2013-01-4 13:10:10.707
User_Confirmation:                       DATA-16687-20120104011007
id_number:            2432
Data_year:            2011-2012


SELECT [Data_id]
      ,[user_submitted]
      ,[user_date_submitted]
      ,[user_confirmation]
      ,[id_number]
      ,[Data_year]
  FROM [ABC].[dbo].[tblDATAInfo]
  where id_number like '2432'


My Question:
------------------------

<p align="center"><a href="http://www.abc.com"><img src="mybutton.jpg" width="100" height="50" border="0"></a></p>


I would like to add a coldfusion code before the button image so that it disappears from my page, once a user has filed the data. This would involve putting some code around the button "mybutton.jpg" that would check the tblDataInfo table for the member's ID number and the Data_year=2011-2012 (in the same record), which is what gets stored in the table (along with some other info), once the member files.

Now, I have a coldfusion page who display that image button.  So I don't want to display the button every time on that page when the user logged again... because he already filled the forms.

So could you please helpm in this , what my new querry should be something like this ?

<cfquery name="DisplayButtons" datasource="ABC" username="#application.username#" password="#application.password#">
      SELECT * FROM tblDATAInfo
         WHERE (id_number = #client.user_id#) and
        (Data_Year = '2011-2012')
</cfquery>

Then my coldfusion code will be:

<cfif .....
0
Comment
Question by:koila
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 38744357
Just check the query recordCount. If it's 0, they haven't filed yet, so show the button.


<cfif DisplayButtons.recordCount eq 0>
       show the button
</cfif>

(Also, it's a good practice to always use cfqueryparam to prevent sql injection. Edit Not sure of your data types, but something like this:  )

         SELECT id_number 
         FROM    tblDATAInfo
         WHERE id_number = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer"> 
         AND   Data_Year = <cfqueryparam value="2011-2012" cfsqltype="cf_sql_varchar">

Open in new window

0
 
LVL 4

Author Comment

by:koila
ID: 38744362
_Agx, Happy New Year.

Could you please fix my query ?

<cfquery name="DisplayButtons" datasource="ABC" username="#application.username#" password="#application.password#">
      SELECT * FROM tblDATAInfo
         WHERE (id_number = #client.user_id#) and
        (Data_Year = '2011-2012')
</cfquery>
0
 
LVL 4

Author Comment

by:koila
ID: 38744365
Once my querry is correct what <CFIF i should put before the button.
<p align="center"><a href="http://www.abc.com"><img src="mybutton.jpg" width="100" height="50" border="0"></a></p>
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 4

Author Comment

by:koila
ID: 38744374
In order for the button to disappear, you would need to develop code that would check that table for the member's ID number and the 2011-2012 data in the same record, for the button to NOT display.  You need to use both fields since there is data in that table from previous years. Let me know if that's not clear.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 38744386
This is what it should look like. You just need to pass in the right year. Let me know if you need help with that part.

<!--- check for existing records for year 2011-2012 --->
<cfquery name="DisplayButtons" datasource="ABC" username="#application.username#" password="#application.password#">
  SELECT id_number
         FROM    tblDATAInfo
         WHERE id_number = <cfqueryparam value="#client.user_id#" cfsqltype="cf_sql_integer">
         AND   Data_Year = <cfqueryparam value="2011-2012" cfsqltype="cf_sql_varchar">
</cfif>

<!---- If no records were found, go ahead and show the button ---->
<cfif DisplayButtons.recordCount eq 0>
    <p align="center">
     <a href="http://www.abc.com"><img src="mybutton.jpg" width="100" height="50" border="0"></a>
     </p>
</cfif>
0
 
LVL 4

Author Comment

by:koila
ID: 38744422
I will review this in one hour.
0
 
LVL 4

Author Comment

by:koila
ID: 38744832
Hello Agx,

Your code didn't work.  I did the following code and it's working.

I have a question for you, how i'm able to reverse the CFistatement

      <cfif DisplayUser.DATA_submitted eq 1>
               &nbsp;

<cfelse>
          <p align="center">
     <a href="http://www.abc.com"><img src="mybutton.jpg" width="100" height="50" border="0"></a></cfif>
0
 
LVL 4

Author Closing Comment

by:koila
ID: 38744835
Please let me know about cfif how i can reverse it.

Thank you.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38744839
Oh, I thought you wanted to display the button if the record *didn't* exist.  If it's the other way around, then your code is right.  Though to be safe you might use GTE 1. So it'll still work if there's ever more than 1 record.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38744859
> <cfif DisplayUser.DATA_submitted eq 1>

Oh wait a minute ... ignore my last comment.  I see the problem. You're not using the recordCount like in my example. It should be this instead:

        <cfif DisplayButtons.recordCount eq 0>
  <p align="center">
     <a href="http://www.abc.com"><img src="mybutton.jpg" width="100" height="50" border="0"></a>
        </cfif>
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question