Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Issue using MAX() function

    Hey, the following code works if I don't use the MAX() function and replace it with *

    All I want to do is get the largest value in the img_set column for the specific date.

    Code:
    'How many image sets is there
    query_set = "SELECT MAX(img_set) FROM images WHERE DATEVALUE(upload_date_time) = "&ISODate(getdate)
    rs.Open query_set, conn
    				
    do
    	response.Write "<"&rs("img_set") & "><br />"
    	rs.MoveNext
    loop while not rs.EOF
    				
    rs.close
    conn.close
    Getting the following error
    Code:
    ADODB.Recordset error '800a0cc1'
    
    Item cannot be found in the collection corresponding to the requested name or ordinal.
    
    /nightclub_photography/pages/rotate.asp, line 35
    Last edited by martynball; 06-27-2013 at 12:11 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    Two ways:
    Code:
    query_set = "SELECT MAX(img_set) FROM images WHERE DATEVALUE(upload_date_time) = "&ISODate(getdate)
    Set rs = conn.Execute(query_set)
    Response.Write rs(0)
    ** OR **
    Code:
    query_set = "SELECT MAX(img_set) AS frambolitzi FROM images WHERE DATEVALUE(upload_date_time) = "&ISODate(getdate)
    Set rs = conn.Execute(query_set)
    Response.Write rs("frambolitzi")
    (a) There can NEVER be a need for a DO loop here. As written, the query is *GUARANTEED* to always and only return *ONE* record.
    (b) No, you don't have to name it "frambolitzi". <grin/>
    (c) Using conn.Execute means you do *NOT* have to do Set rs = Server.CreateObject("ADODB.Recordset") *AND* it executes a bit faster.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (06-27-2013)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    But this code can't possibly be right:
    Code:
    response.Write "<"&rs("img_set") & "><br />"
    That will create an HTML tag with a name equal to your table field value.

    Surely you don't expect that to work, except for a few names? <flowers><br/>????
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (06-27-2013)

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Thanks! And I used "<, >" simply so I could see the numbers easier without getting them confused with other content on the page. Probably shouldn't of used that character really lol

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    What the heck is going on here? I don't see why it isn't working.

    imageset = 1. Basically the class on the first li should be "num_number nsel" and on the rest just "num_number"

    PHP Code:
    if maxamount 1 then
                        Response
    .Write "<span class='num'>"
                            
    Response.Write "<ul>"
                                
    Response.Write "<li>Upload Set:</li>"
                                
    for 1 to maxamount
                                    
    if imageset then
                                        g 
    " nsel"
                                    
    else 
                                        
    ""
                                    
    end if
                                    
    'Response.Write "<li class='num_number"&g&"'"&_
                                                    '"onClick=""loadDoc('main','pages/rotate.asp?imageset="
    &i&"',1)"">"&i&"</li>"
                                                    
    response.Write("("&i&g&")")
                                
    next
                            Response
    .Write imageset&"</ul>"
                        
    Response.Write "</span>"
                    
    end if 

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    The *FIRST* <li>??? This one:
    Code:
    Response.Write "<li>Upload Set:</li>"
    ???

    Then why not just hard code it?

    Or you mean then Nth one *AFTER* that one, where N is imageset?

    If the latter, then I don't see anything wrong with what you showed.

    What does it look like when you do a VIEW-->>SOURCE in the browser?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    But this is illegal HTML:
    Code:
    Response.Write imageset&"</ul>"
    you can't have non-<li> content between <ul> and </ul>.

    imageset is just a number, and it's not contained withing an <li> element.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (06-27-2013)

  • #8
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    That illegal HTML was just to test things, forgot to remove it.

    And yeah I meant the Nth one, I have replaced the "li" with some debugging code. Just put "h" in the g variable to see if the variable is actually working.

    What SHOULD be displayed
    Code:
    (1nsel)(2h)(3h)
    But what IS displayed
    Code:
    (1h)(2h)(3h)
    PHP Code:
    if maxamount 1 then
                        Response
    .Write "<span class='num'>"
                            
    Response.Write "<ul>"
                                
    Response.Write "<li>Upload Set:</li>"
                                
    for 1 to maxamount
                                    g 
    "h"
                                    
    if imageset then
                                        g 
    " nsel"
                                    
    end if
                                    
    response.Write("("&i&g&")")
                                
    next
                            Response
    .Write "</ul>"
                        
    Response.Write "</span>"
                    
    end if 

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    Hmmm...and how do you know the value of imageset??

    Possibly it is coming in as a string, not a number?

    Maybe you just need to do imageset = CINT(imageset) ???

    How about change this debug line
    Code:
          response.Write("("&i&g&")")
    to
    Code:
          response.Write "(" & i & "?" & imageset & ":" & g & ")"
    And you keep putting those extra parentheses into your response.write's! <grin/>
    Last edited by Old Pedant; 06-27-2013 at 04:24 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (06-27-2013)

  • #10
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    imageset = CINT(imageset) worked. It was fetching the imageset value from a url variable if it existed which in turn returned a string.


  •  

    Posting Permissions

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