Solved

<cfquery name  <cfif

Posted on 2013-01-04
10
448 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
  • 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
COLD FUSION 6 25
ColdFusion Web Service/WSDL Connection Issue 2 89
Browser back button refreshing coldfusion iframe 6 72
popup load of page and setting up of session 8 26
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
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 …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now