Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

<cfquery name  <cfif

Posted on 2013-01-04
10
Medium Priority
?
458 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

927 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