SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    australia
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Where am i going wrong...?

    Hi guys,

    i am playing with an IF statement and when i change the values manually it works fine but when the page is loaded it wont read the values only shows the table selected from the initial value.

    <%
    dim accessories
    value accessories = 0
    if accessories = 1 then
    %>

    <table> empty layout table 1</table>

    <%
    elseIF accessories=1 then
    %>

    <table> empty layout table 2</table>

    <%
    else accessories=0 then
    %>

    <table> empty layout table 2</table>

    <% end if %>

    this is all i have that relates to this script, although there are other scripts on the page for various items and also for the database connection

    any help would be great,

    Thanks.

    Angelo.

  2. #2
    HardCoder md_irfan_amu's Avatar
    Join Date
    May 2005
    Location
    Asia
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <%
    dim accessories
    value accessories = 0
    if accessories = 1 then
    %>

    <table> empty layout table 1</table>

    <%
    elseIF accessories=1 then
    %>

    <table> empty layout table 2</table>

    <%
    else accessories=0 then
    %>

    <table> empty layout table 2</table>

    <% end if %>
    why u r using two if one if and other elseif for the same condition....

    if accessories = 1 then
    elseIF accessories=1 then

    i cant find what u wanna do clear it
    Irfan
    Find Tutors Easyway to get connect with your tutor in india

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    australia
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry it is actually as follows:

    <%
    dim accessories
    value accessories = 0
    if accessories = 1 then
    %>

    <table> empty layout table 1</table>

    <%
    elseIF accessories=2 then
    %>

    <table> empty layout table 2</table>

    <%
    else accessories=0 then
    %>

    <table> empty layout table 2</table>

    <% end if %>

  4. #4
    HardCoder md_irfan_amu's Avatar
    Join Date
    May 2005
    Location
    Asia
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can u tell me from where u r getting the value of accessories wheather by post , querystring ,,,, however why u write value accessories = 0 just remove value from here..
    and write the code from which u r getting the value of accessories.
    Irfan
    Find Tutors Easyway to get connect with your tutor in india

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    australia
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok all i have done is set up the database to have numerical options (Value 1, Value 2 )that are submited from an admin point, on the page where this script will be will also be other scripts to open the database and that table but i dont know how to define the values for this, i am a beginner and dont know what to do. if you could give me an idea

    i want to show table 1 if the value in the database is 1 then a different table 2 if the value is 2 and so on.

    thanks in advance

  6. #6
    HardCoder md_irfan_amu's Avatar
    Join Date
    May 2005
    Location
    Asia
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u just open then table and with the help of sql statements select the field from data base and hence the value will get after that u chack the condition ,, this will work fine.. but first u get the valu from the data base (table)
    Irfan
    Find Tutors Easyway to get connect with your tutor in india

  7. #7
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    australia
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry this doesn't he;p can you show me with code, is what i have used above correct, do i need to open a seperate connection to the database from the page even if the connection is open and pointint to that table.

    Can you please show me.

  8. #8
    HardCoder md_irfan_amu's Avatar
    Join Date
    May 2005
    Location
    Asia
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you didnt write the code in your post where u open the connection..

    if already open no need to reopnw but you should take the recordset to point the data actalyy like

    dim rs,str
    set rs = server.createobject("adodb.recordset")
    str = "select fieldname from table where condition if needed"
    set rs = con.execute(str) //con is connection u open fro database..//

    now u will get a recordsourse having ur value;;;

    accessories = rs("fieldname");
    now u check and find appropriate table..
    Irfan
    Find Tutors Easyway to get connect with your tutor in india

  9. #9
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    australia
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i already have a connection to the database:

    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open dbConnectionStr
    if isNumberValid(session("eCart_membershipID")) AND session("eCart_membershipID") > 0 then
    SQLQuery = "SELECT tblProducts_Categories.categoryID FROM tblProducts_Categories WHERE tblProducts_Categories.productID=" & productID & ";"
    else
    SQLQuery = "SELECT tblProducts_Categories.categoryID FROM tblProducts_Categories INNER JOIN tblCategory ON tblProducts_Categories.categoryID = tblCategory.categoryID WHERE tblProducts_Categories.productID=" & productID & " AND tblCategory.hidden = " & prepBoolean("false") & ";"
    end if

    i think the issue is here

    <%
    dim accessories
    accessories = 0 < 9
    if accessories = 1 then
    %>


    <table> empty layout table 1</table>

    <%
    elseIF accessories=2 then
    %>

    <table> empty layout table 2</table>

    <%
    else accessories=0 then
    %>

    <table> empty layout table 0</table>

    <% end if %>

  10. #10
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi dallas,

    I'll be able to help you if you answer these questions:

    1. Which database field is used to populate accessories? Presumably it must be tblProducts_Categories.categoryID as that's the only field you're currently selecting?

    2. What is the type of this field in the database? (e.g. varchar, text, int, etc.)

    In the meantime, I strongly advise you do two things:

    1. Response.Write your SQL string, the YourRecordsetObject("categoryID") and the final value of the 'accessories' variable to the screen at the top of the page - this way you can see exactly what goes wrong and where (is it malformed SQL? - unlikely as I'd expect an error, but check anyway - is it returning an unexpected value? is it not populating your variable correctly?)

    2. Change the If statement you're using with the 'accessories' variable to a Select Case. This is a more efficient way of handling the sort of decision you have here. It's just better practice.

    Look forward to your responses.

    Cheers,

    G


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
  •