RecordCount question

Discussion in 'Programming' started by TerriKat, May 27, 2008.

  1. #1
    I'm trying to use a database to keep track of login members' uploaded pictures. Each member has an id (Faculty_ID), then every image they upload has a number assigned to it. The problem I'm running into is that the members who haven't uploaded anything yet end up with an error.

    <cfquery datasource="faculty" name="Image">
    SELECT max(ImageNo) FROM Faculty_Artwork WHERE Faculty_ID = #fid#
    </cfquery>
    <cfif Image.RecordCount EQ "0">
    <cfset imageno=1>
    <cfelse>
    <cfset number=Image.expr1000>
    <cfset imageno= #number#+1>
    </cfif>

    I thought Image.RecordCount would be 0 if there's no files in the database with that Faculty_ID, but it ends up set to 1, thus causing coldfusion to use the wrong part of the if. Any suggestions? I'm very new to coldfusion.
     
    TerriKat, May 27, 2008 IP
  2. apmsolutions

    apmsolutions Peon

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your recordcount WILL be 1. That is because it will always return 1 record, just because of the way you wrote your query.

    Alias your max(ImageNo) in your current query, then do the <cfif on imageNo.aliasname is 0>.
     
    apmsolutions, May 27, 2008 IP
  3. TerriKat

    TerriKat Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I see what you mean: I'm getting a RecordCount of one (which apparently is whatever number is #fid# under the name ID) and a ColumnList of EXPR1000.
    What exactly in the query's statment is doing that?

    Also, what do you mean by alias and how do you do that? (I apologize for asking what is likely a noob question, I'm learning all this on the fly.)
     
    TerriKat, Jun 6, 2008 IP
  4. websiteideas

    websiteideas Well-Known Member

    Messages:
    1,406
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    130
    #4
    I think what he means is to use this: SELECT max(ImageNo) AS aliasname
    instead of this: SELECT max(ImageNo)

    and then <cfif on image.aliasname is 0>.
     
    websiteideas, Jun 6, 2008 IP
  5. apmsolutions

    apmsolutions Peon

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry, yes. Alias is giving a column or computed column a name that you can reference.
     
    apmsolutions, Jun 8, 2008 IP