Solved

<cfquery name  <cfif

Posted on 2013-01-04
10
455 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

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 …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

632 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