Solved

<cfquery name  <cfif

Posted on 2013-01-04
10
444 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

9 Experts available now in Live!

Get 1:1 Help Now