Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 26

Discussione: ciclo for

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    119

    ciclo for

    Devo dire di stamparmi la variabile prezzo solo quando è presente nel db e credo di aver bisogno di un ciclo for.

    Qualcuno mi dice come?

    SEGUE CODICE:

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <%
    function getMese(ByVal mese)
    if not isNumeric(mese) then exit function
    getMese=arrMesi(mese-1)
    end function

    function giorniMese(mese,anno)
    dim giorni
    Select Case cint(mese)
    Case 1,3,5,7,8,10,12:
    giorni = 31
    Case 4,6,9,11:
    giorni = 30
    Case 2:
    if ((cint(anno) mod 4 = 0 and _
    cint(anno) mod 100 <> 0) _
    or ( cint(anno) mod 400 = 0) ) then
    giorni = 29
    else
    giorni = 28
    end if
    End Select
    giorniMese = giorni
    end function

    arrMesi=Array("Gennaio","Febbraio","Marzo","Aprile ","Maggio","Giugno","Luglio","Agosto","Settembre", "Ottobre","Novembre","Dicembre")


    %>
    </head>

    <body>
    <%
    dim mese, settimana, prezzo,rif
    mese= Request.QueryString("mese")
    settimana = Request.QueryString("settimana")
    prezzo = Request.QueryString("prezzo")
    rif = Request.QueryString("rif")


    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open "provider=microsoft.jet.oledb.4.0; data source="& Server.MapPath("/offerte/offerte.mdb")
    Set Rs = Server.CreateObject("ADODB.Recordset")
    sql =" select * from disponibilita "
    Rs.Open sql, Conn, 1, 3
    %>

    <table width="450" border="0" cellpadding="0" cellspacing="0">
    <%


    While NOT rs.EOF

    mese=month(date())
    for i=mese to 12

    Response.Write" <tr><td>" & getMese(i) & "</td>"
    primo=datePart("W","01/" & i & "/" & year(date()))
    if primo=7 then
    start=1
    else
    start=1+(7-primo)
    end if
    nGiorni=giorniMese(i,year(date()))
    %>

    <%
    for y=start to nGiorni
    Response.Write"<td>" & y & "</td> <td>" & Rs("prezzo") & "</td>"
    y=y+6
    next
    Response.Write"</tr>"
    next
    %>
    <%
    rs.MoveNext
    Wend
    %>

    </table>
    <%
    rs.close
    set rs = nothing
    conn.close
    set conn = nothing
    %>


    </table>
    </body>
    </html>

  2. #2
    Utente di HTML.it L'avatar di madai
    Registrato dal
    Oct 2000
    Messaggi
    421
    If Rs("prezzo") <> "" and isNumeric(Rs("prezzo")) then



    intendi questo controllo?
    Sviluppo web
    Cerchi un hotel a Ischia dove si mangia si beve e si fischia? Scegli ProntoIschia ed il portafoglio non rischia.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    119
    Ma dove lo inseriresti

  4. #4
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    119
    Io avrei bisogno di dire che per ogni variabile y uguale a settimana (prente nel DB) devo inserire il prezzo oppure di che non è disponibile.

    Faccio così

    for y=start to nGiorni
    Response.Write"<td>" & y & "</td>"

    If Rs("prezzo") <> "" and isNumeric(Rs("prezzo")) then
    Response.Write"<td>" & Rs("prezzo") & "</td>"
    else
    Response.Write"<td>ND</td>"
    end if
    y=y+6
    next

    però mi stampa il prezzo uguale in tutte le celle

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    254
    codice:
    for y=start to nGiorni 
    Response.Write"<td>" & y & "</td>"
    if y=settimana then
    If Rs("prezzo") <> "" and isNumeric(Rs("prezzo")) then
    Response.Write"<td>" & Rs("prezzo") & "</td>"
    rs.movenext
    else
    Response.Write"<td>ND</td>"
    end if
    y=y+6    'perchè incrementi y di 6?
    next

  6. #6
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    119
    +6 perchè le settimane partono da sabato.

    Il tuo codice però mi dice che il next non è previsto. In più stampa tutti ND.

    Codice:

    <%

    function getMese(ByVal mese)
    if not isNumeric(mese) then exit function
    getMese=arrMesi(mese-1)
    end function

    function giorniMese(mese,anno)
    dim giorni
    Select Case cint(mese)
    Case 1,3,5,7,8,10,12:
    giorni = 31
    Case 4,6,9,11:
    giorni = 30
    Case 2:
    if ((cint(anno) mod 4 = 0 and _
    cint(anno) mod 100 <> 0) _
    or ( cint(anno) mod 400 = 0) ) then
    giorni = 29
    else
    giorni = 28
    end if
    End Select
    giorniMese = giorni
    end function

    arrMesi=Array("Gennaio","Febbraio","Marzo","Aprile ","Maggio","Giugno","Luglio","Agosto","Settembre", "Ottobre","Novembre","Dicembre")


    %>
    <%
    dim mese, settimana, prezzo,rif
    mese= Request.QueryString("mese")
    settimana = Request.QueryString("settimana")
    prezzo = Request.QueryString("prezzo")
    rif = Request.QueryString("rif")


    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open "provider=microsoft.jet.oledb.4.0; data source="& Server.MapPath("/offerte/offerte.mdb")
    Set Rs = Server.CreateObject("ADODB.Recordset")
    sql =" select rif from disponibilita where mese = '"&mese&"' and settimana = '"&y&"'"
    Rs.Open sql, Conn, 1, 3
    %>

    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tblcalendar">
    <%




    mese=month(date())
    for i=mese to 12

    Response.Write" <tr><td width='15%'>" & getMese(i) & "</td>"
    primo=datePart("W","01/" & i & "/" & year(date()))
    if primo=7 then
    start=1
    else
    start=1+(7-primo)
    end if
    nGiorni=giorniMese(i,year(date()))
    %>

    <%
    for y=start to nGiorni
    Response.Write"<td>" & y & "</td>"
    if y=settimana then
    'If Rs("prezzo") <> "" and isNumeric(Rs("prezzo")) then
    Response.Write"<td class='dispo'>" & Rs("prezzo") & "</td>"
    rs.movenext
    else
    Response.Write"<td class='ndispo'>ND</td>"
    end if
    y=y+6 'perchè incrementi y di 6?
    next
    Response.Write"</tr>"
    next
    %>


    </table>
    <%
    rs.close
    set rs = nothing
    conn.close
    set conn = nothing
    %>

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    254
    +6 perchè le settimane partono da sabato.
    si, ma se devi passare da una settimana alla successiva devi aggiungere 7 giorni, no?

    per quanto riguarda l'errore, non ho capito quale istruzione ti dà l'errore

  8. #8
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    119
    Errore di compilazione di Microsoft VBScript error '800a041f'

    'Next' non previsto

    for y=start to nGiorni
    Response.Write"<td>" & y & "</td>"
    if y=settimana then
    If Rs("prezzo") <> "" and isNumeric(Rs("prezzo")) then
    Response.Write"<td class='dispo'>" & Rs("prezzo") & "</td>"
    rs.movenext
    else
    Response.Write"<td class='ndispo'>ND</td>"
    end if
    y=y+6 'perchè incrementi y di 6?
    next
    Response.Write"</tr>"
    next
    %>

  9. #9
    Utente di HTML.it
    Registrato dal
    Jul 2003
    Messaggi
    254
    manca la chiusura dell'if

    codice:
    for y=start to nGiorni 
    Response.Write"<td>" & y & "</td>"
    if y=settimana then
    If Rs("prezzo") <> "" and isNumeric(Rs("prezzo")) then
    Response.Write"<td class='dispo'>" & Rs("prezzo") & "</td>"
    rs.movenext
    
    else
    Response.Write"<td class='ndispo'>ND</td>"
    end if 
    else
    Response.Write"<td class='ndispo'>ND</td>"
    end if
    y=y+6 
    next 
    Response.Write"</tr>"
    next

  10. #10
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    119
    Ora funziona. L'unica cosa che mi stampa sempre ND e non prezzo
    Eppure il Db è pieno

    IDdisponibilita rif anno mese settimana prezzo disponibile
    1 A021 2006 7 1 350 Si
    2 A021 2006 7 8 560 No
    3 A021 2006 7 15 650 Si
    5 A021 2006 7 22 425 No
    13 A021 2006 7 29 300
    14 A021 2006 8 5 350 Si
    15 A021 2006 8 12 560 No
    16 A021 2006 8 19 650 Si
    17 A021 2006 8 26 425 No
    18 A021 2006 9 2 300
    19 A021 2006 9 9 350 Si
    20 A021 2006 9 16 560 No
    21 A021 2006 10 7 650 Si
    22 A021 2006 10 14 425 No
    23 A021 2006 10 21 300
    24 A021 2006 10 28 350 Si
    25 A021 2006 11 4 560 No
    26 A021 2006 11 11 650 Si
    27 A021 2006 11 18 425 No
    28 A021 2006 11 25 300
    29 A021 2006 12 2 560 No
    30 A021 2006 12 9 650 Si
    31 A021 2006 12 16 425 No
    32 A021 2006 12 23 300
    33 A021 2006 12 30 300

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.