How do I evaluate a variable against a Query Result

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default How do I evaluate a variable against a Query Result

    I have script that generates a variable containing the client ip adress.
    and I want to check if this ip adress is allready in a specific table.column.

    How do I do that, I have tried with
    <cfquery name="recordsetvariable" datasource="MyDatabase">
    SELECT ip_adress FROM ip_table
    <cfquery>

    <cfif #recordsetvariable# DOES NOT CONTAIN <#browseripadress#>
    Further flow of the pogram.
    But it seems I cant get it to work.
    Anybody any ideas?

    scdebaay Guest

  2. Similar Questions and Discussions

    1. Can't Evaluate External Variable in 'Expressions' Window
      Greetings, I'm new to Flex and am trying to figure out how to evaluate the static property of an external class when a breakpoint is hit. The...
    2. problems with evaluate-function and " ' " in query
      hello. strange problem. let's say i have the following variable: cfset content = "let's rock" if i make an insert-query into a ms sql server...
    3. Stored Procedure Result Variable
      I am having trouble returning variables from my stored procedures. My CFML and SP code is attached. The error is always: Attribute validation...
    4. How to deal with big query result?
      Greetings, In my search application, user can type a number to search. I use LIKE in my query. If a query result generates over 10,000...
    5. How to declare the result of a loop as a variable?
      I'm trying to include a list of people that's the result of looping through a recordset in a CDONTS mail. I'm trying to Dim the output of a loop,...
  3. #2

    Default Re: How do I evaluate a variable against a Query Result

    See attached code.

    HTH

    <!--- you could do it directly in the query --->
    <cfquery name="recordsetvariable" datasource="MyDatabase">
    SELECT ip_adress
    FROM ip_table
    WHERE ip_address = '#browseripadress#'
    <cfquery>


    <!--- or use cold fusion --->

    <!--- do your query to get all ip addresses --->
    <cfquery name="recordsetvariable" datasource="MyDatabase">
    SELECT ip_adress
    FROM ip_table
    <cfquery>

    <!--- check if the ip address is in the list of values found in the query --->
    <cfif ListFind(ValueList(recordsetvariable.ip_address), browseripadress)>
    blah blah
    </cfif>

    <!--- or loop over whole query --->
    <CFLOOP QUERY="#recordsetvariable#">
    <CFIF ip_address EQ browseripadr>
    blal blah
    </CFIF>
    </CFLOOP>

    <!--- or use a query of query - don't know what you are doing so this may suit
    your purpose --->
    <cfquery name="thisRecord" DBTYPE="QUERY">
    SELECT ip_adress
    FROM recordsetvariable
    WHERE ip_address = '#browseripadress#'
    <cfquery>

    zoeski80 Guest

  4. #3

    Default Re: How do I evaluate a variable against a Query Result

    Wow!

    Thanx a lot!
    Don't have time to test it now, but I will be working on it soon!

    The thing is, I want to check wether the IP exists in the table, and if it
    doesn't, add a record in the table for that adress.

    Any idea on how to construct that?
    But, thanks again, I think this might be a good help.
    Did'nt know about the ListFind Function ;o)

    Greetz

    scdebaay Guest

  5. #4

    Default Re: How do I evaluate a variable against a Query Result

    scdebaay,

    You could use NOT EXISTS to insert the ip address only if it does not already
    exist in your table. The exact syntax may vary depending on your database
    type. This example works with mySQL 5.



    <cfquery name="addRecord" datasource="MyDatabase">
    INSERT INTO ip_table (ip_adress)
    SELECT '#browserIPAdress#'
    FROM dual
    WHERE NOT EXISTS (
    SELECT 1
    FROM ip_table
    WHERE ip_adress = '#browserIPAdress#'
    )
    </cfquery>

    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139