Selecting Multiple Rows from DB

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

  1. #1

    Default Selecting Multiple Rows from DB

    I'm building code where I need to be able to read all the rows in a single
    column of data. My SQL code currently is simple and looks like this:

    Code:
    SELECT column
    FROM table
    and sure enough, if I do a cfdump on the query it returns all rows. Here's
    the conflict, the result goes into an if statement like this (NOT a cfoutput or
    cfloop):

    Code:
    <cfif query.column eq #variable#>
    I need the #variable# to be able to match ANY of the returned rows in the
    column, not just the first row (as it is doing now). I thought I'd be able to
    achieve this using a WHERE clause in the SQL statement, but have had no luck
    thus far. DOes anyone have an idea how I might achieve this?

    I hope this isn't too vague. Please let me know if I need to elaborate.

    Thanks for your time in advance.

    Ultrashock Guest

  2. Similar Questions and Discussions

    1. selecting based on matches on multiple rows?
      I thought this would be simple, but it has me stumped. I've got items that have attributes. Attributes are of the form "name=value", where "name"...
    2. Selecting and Highlighting Multiple Rows in a DataGrid
      I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which...
    3. SELECTING ROWS
      Hi again Im trying to select a particular ROW in my Database, I want to run a query on the 1st 2nd and 3rd rows seprately. the information will...
    4. Datagrid: Selecting multiple rows/cols
      Hi, I would like to enhance the DataGrid by adding scripting functionality that allows the selection of multiple rows or columns via...
    5. DataGrid: Selecting multiple rows/columns
      Hi, I would like to enhance the DataGrid by adding scripting functionality that allows the selection of multiple rows or columns via...
  3. #2

    Default Re: Selecting Multiple Rows from DB

    The best method depends on what you're trying to do. Do you need a list of the
    actual query.Column values for usage somewhere else in your page, or are you
    just testing for the existence of a value (#variable#) in the Table.Column?
    What exactly are you trying to?

    mxstu Guest

  4. #3

    Default Re: Selecting Multiple Rows from DB

    I don't necessarily need a list. It's more along the lines of checking for the
    existance of a value.

    This is what it is in depth.

    I've constructed a dynamic monthly calendar. I have topics written on a
    specific date which I would like to highlight/link the date in the calendar to
    that particular writing. Using the code above, I was able to get the calendar
    to read the date column, but only the data from the first row. In other words,
    the calendar is only linking the first date listed in the database. So maybe I
    need a list of dates, but I think the database itself already provides this
    information. I think it's more along the lines of checking for the existance
    of a date.

    Does that help? Thanks again for your time.

    Ultrashock Guest

  5. #4

    Default Re: Selecting Multiple Rows from DB

    Well, if it's a calendar app, then I'm assuming you're doing some looping, in
    which case hitting the database numerous times might not be such a great idea.
    You could use the ValueList() function to convert the query column results to a
    list and then use ListFind() or ListFindNoCase() to determine if the #variable#
    exists in the list.




    <cfset myList = ValueList(myQuery.myColumnName)>
    <cfif ListFindNoCase(myList, variable) GT 0>
    Value found... do something
    <cfelse>
    Not found
    </cfif>

    mxstu Guest

  6. #5

    Default Re: Selecting Multiple Rows from DB

    This didn't do it either, although it didn't error out. Rather than link the
    first date though, it didn't link a date at all. I've attached the code if it
    might help a bit more.

    <cfinvoke component="#Application.DRIVER#" method="calendar"
    returnvariable="calendar">
    <cfparam name = "month" default = "#datepart('m', now())#">
    <cfparam name = "year" default = "#datepart('yyyy', now())#">
    <cfparam name = "currentday" default = "#datepart('d', now())#">
    <cfparam name = "startmonth" default = "#datepart('m', now())#">
    <cfparam name = "startyear" default = "#datepart('yyyy', now())#">
    <cfset thismonthyear = createdate(year, month, '1')>
    <cfset days = daysinmonth(thismonthyear)>
    <cfset lastmonthyear = dateadd('m', -1, thismonthyear)>
    <cfset lastmonth = datepart('m', lastmonthyear)>
    <cfset lastyear = datepart('yyyy', lastmonthyear)>
    <cfset nextmonthyear = dateadd('m', 1, thismonthyear)>
    <cfset nextmonth = datepart('m', nextmonthyear)>
    <cfset nextyear = datepart('yyyy', nextmonthyear)>
    <cfset listlinks = ValueList(calendar.date)> <!--- Build a list for the linked
    days --->
    <table class="calFrame" cellspacing="0" cellpadding="0"> <!--- Month Framework
    --->
    <tr>
    <td>
    <div class="calMonth">
    <cfoutput>
    <a
    href="index.cfm?month=#lastmonth#&year=#lastyear#" ><<</a>#monthasstring(month)#
    #year#<a href = "index.cfm?month=#nextmonth#&year=#nextyear#"> >></a>
    </cfoutput>
    </div>
    <table cellspacing="0" cellpadding="0"> <!--- Sunday - Saturday Header --->
    <tr>
    <cfloop from = "1" to = "7" index = "loopday">
    <cfoutput>
    <td class="calHead">#left(dayofweekasstring(loopday), 1)#</td>
    </cfoutput>
    </cfloop>
    </tr>
    </table>
    <table class="calDayframe" cellspacing="0" cellpadding="0">
    <cfset thisday = 0>
    <cfloop condition = "thisday lte days">
    <tr>
    <cfloop from = "1" to = "7" index = "loopday">
    <cfif thisday is 0>
    <cfif dayofweek(thismonthyear) is loopday>
    <cfset thisday = 1>
    </cfif>
    </cfif>
    <cfif (thisday is not 0) and (thisday lte days)>
    <cfoutput>
    <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#),
    "mm/dd/yyyy")#>
    <cfif (#thisday# eq #currentday#) and (#month# eq #startmonth#) and (#year# eq
    #startyear#)> <!--- Highlight Today --->
    <td class="calToday">
    #thisday#
    </td>
    <cfelse>
    <!--- <cfif calendar.date eq #dayview#> ---> <!--- Linked Days to Entries --->
    <cfif ListFindNoCase(listlinks, dayview) gt 0>
    <td class="calPday">
    <a href="">#thisday#</a>
    </td>
    <cfelse> <!--- Standard Days --->
    <td class="calDay">
    #thisday#
    </td>
    </cfif>
    </cfif>
    </cfoutput>
    <cfset thisday = thisday + 1>
    <cfelse>
    <td></td>
    </cfif>
    </cfloop>
    </tr>
    </cfloop>
    </table>
    </td>
    </tr>
    </table>

    Ultrashock Guest

  7. #6

    Default Re: Selecting Multiple Rows from DB

    I didn't read through all of the code yet, but are you trying to search through
    a list of dates (not strings)? If so, it could very well be that the format of
    the date in the list is different than the variable date. Try outputting the
    ValueList()... and the variable and see if it's a format problem.

    mxstu Guest

  8. #7

    Default Re: Selecting Multiple Rows from DB

    Yes, I just checked this by retrieving 2 date records from my database and
    searching the list for the same date, created with the CreateDate() function.
    It did not work, due to the different date formats. I would assume that
    ListFind() just performs a straight string list search, and does not take into
    account datatypes.




    <!--- format of dates directly from cfquery db query --->
    <cfset dateListFromQuery = "2000-10-01 00:00:00.0,2000-10-01 00:00:00.0">
    <cfset variableDate = CreateDate(2000, 10, 2)>

    <cfdump var="#dateListFromQuery#">
    <cfdump var="#variableDate#">

    <!--- Results in "Not Found" --->
    <cfif ListFind(dateListFromQuery, variableDate) GT 0>
    Found
    <cfelse>
    Not Found
    </cfif>

    mxstu Guest

  9. #8

    Default Re: Selecting Multiple Rows from DB

    Yes it was a format problem... thanks for calling me on that. I was able to put a simple DateFormat on the dayview variable in the if statement and voila!

    Thanks so much for your time! :)
    Ultrashock 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