SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with if statement in response.write

    i am trying to get a response if there are no records listed in field "venue"

    what am i doing wrong please. both records with and without venue listing are showing "Venue Details" the ones without a records should be showing "none"

    Code:
     <%
    Set objRs = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT Count(venue) AS `venuecount` FROM `gigs` GROUP BY `Contact`"
    objRS.Open strSQL, objconn
    IF objRS.EOF AND objRS.BOF THEN
    	Response.Write "none"
    ELSE
    	Response.Write "<venuedetails.asp>Venue Details</a>"
    	venuecount = objRS("venuecount")
    END IF
    objRs.Close
    %>

  2. #2
    SitePoint Addict WolfShade's Avatar
    Join Date
    Mar 2014
    Location
    St. Louis, MO, USA
    Posts
    253
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No matter what, since you're requesting a COUNT(), you'll always get ONE record. Instead of checking for an empty query object, get the count value. If it's 0, then write 'none'; else do the response.write.

    HTH,

    ^_^

  3. #3
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WolfShade View Post
    No matter what, since you're requesting a COUNT(), you'll always get ONE record. Instead of checking for an empty query object, get the count value. If it's 0, then write 'none'; else do the response.write.

    HTH,

    ^_^
    i am getting error if i just do IF venue=0

    <%
    Set objconn = Server.CreateObject("ADODB.Connection")
    objconn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=xxx; PORT=3306; DATABASE=xxx; UID=xxx; PASSWORD=xxx; OPTION=3"
    objconn.Open
    Set objRs = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT Count(*) AS `venue` FROM `gigs` GROUP BY `Contact`"
    objRS.Open strSQL, objconn
    IF venue = 0
    Response.Write "no bookings"
    ELSE

    Response.Write "Venue Details"

    venue = objRS("venue")
    END IF
    objRs.Close
    %>

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what's the error message ?

  5. #5
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    what's the error message ?
    this is what i have on the page

    Code:
    	<%
    Set objconn = Server.CreateObject("ADODB.Connection")
    objconn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=xxx; PORT=3306; DATABASE=xxx; UID=xxx; PASSWORD=xxx; OPTION=3"
    objconn.Open
    Set objRs = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT Count(*) AS `venuecount` FROM `gigs` WHERE Contact='"&strContact&"'"
    
    objRS.Open strSQL, objconn
    IF venuecount = 0 THEN
    	Response.Write "hidden"
    ELSE
    	Response.Write "show bookings"
        
    END IF
    objRs.Close
    %>
    i get the response "HIDDEN"
    but this act has gigs so it should display "show bookings"

  6. #6
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My best guess is there is a problem with your SQL statement

    try writing out the sql to see if it producing the desired result:

    Response.write (strSQL)

  7. #7
    SitePoint Addict WolfShade's Avatar
    Join Date
    Mar 2014
    Location
    St. Louis, MO, USA
    Posts
    253
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    One query shows "SELECT COUNT(*) AS `venue`.." and the other shows "SELECT COUNT(*) as `venuecount`.." Make sure you are using the correct alias for output.

    Also, 'venuecount' is not a variable, it is a value from a query object; you need to prepend 'venuecount' with the name of the query object.

    HTH,

    ^_^

  8. #8
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,263
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by WolfShade View Post
    Also, 'venuecount' is not a variable, it is a value from a query object; you need to prepend 'venuecount' with the name of the query object.
    Yup - this is what's getting you. Wrap the venutcount with the queryobject - objRS("venuecount")
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  9. #9
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WolfShade View Post
    Also, 'venuecount' is not a variable, it is a value from a query object; you need to prepend 'venuecount' with the name of the query object.
    Quote Originally Posted by DaveMaxwell View Post
    Yup - this is what's getting you. Wrap the venutcount with the queryobject - objRS("venuecount")
    Totally missed that, good catch guys.


Bookmarks

Posting Permissions

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