Pagina 1 di 5 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 42

Discussione: Commenti (7)

  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    32

    Commenti (7)

    Salve ragazzi, vorrei si vedesse il numero dei commenti in home sul mio sito, come contarli?

    Ho un database.mdb con interni "news" e "commenti" e proprio questo fatto che sono due separate le ho chiamate RecSet e Rs, dove sto sbagliando?

    In sostanza se metto in fondo WHERE pagina ='93'" per esempio mi fa la somma dei commenti tipo 6006, ma COME FACCIO A PASSARE LO STESSO ID DELLA NEWS?



    <%
    url_DB = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("/mdb-database/database.mdb")
    Set Conn = Server.CreateObject("ADODB.Connection")
    conn.Open url_DB
    Set RecSet = Server.CreateObject("ADODB.Recordset")
    SQL = "SELECT TOP 10 * FROM news WHERE Category ='Events' ORDER BY ID DESC"
    RecSet.Open SQL, Conn, adOpenStatic, adLockOptimistic
    If RecSet.Eof = False Then

    set rs=conn.execute ("Select SUM(pagina) as totale from comments WHERE pagina =(ID)")
    %>






    <TABLE width="600" cellSpacing="0" cellPadding="0" border="0">
    <tr>
    <TD vAlign=top align="right" width=74%>
    <DIV id=header_boxes style="WIDTH: 610px; border-top: #cdcdcd 1px solid; padding-left: 0px; padding-top: 10px; margin-bottom: -12px; FLOAT: left; background: #ffffff; FONT-SIZE: 0.9em FONT-FAMILY: Helvetica, Arial, sans-serif; FLOAT: left; COLOR: #555"><H1>Events</H1></DIV>
    <h4 class="clearfix">
    <span class="date">[img]2011/rss.png[/img] Click & subscribe Riders feed</span>
    </h4></td>
    <TD vAlign=top width=26%></td>
    </tr>

    <%
    ' VISUALIZZA LE PRIME 10 NEWS
    Do until RecSet.Eof
    %>

    <TR style="WIDTH: 620px; border-bottom: #cdcdcd 1px solid; padding-bottom: 8px; padding-top: 9px; FLOAT: left; background: #ffffff;

    FONT-SIZE: 0.90em FONT-FAMILY: Helvetica, Arial, sans-serif; FLOAT: left; COLOR: #555">

    <TD vAlign=top width=26%>
    <h4 class="clearfix">
    <span class="date">[img]system/pt.gif[/img]<%=RecSet("Date")%></span>
    </h4>
    <span class="photo"><a href='read_news_comments.asp?id=<%=RecSet("id")%>' class="photo">[img]<%=RecSet("Preview")%>[/img]</span>
    </a>
    </td>
    <TD vAlign=top width=74%>

    <DIV style="margin-left: 0px; margin-top: 1px; FLOAT: left; FONT-FACE: inherit">
    "><span class="title"><%=RecSet("Title")%></span>
    <span class="subtitle"><DIV style="FONT-SIZE: 1.0em; FONT-FAMILY: Helvetica, Arial, sans-serif; color: #777777"><%=RecSet("Subtitle")%></div></span>
    </div>

    <DIV style="margin-left: 0px; margin-top: 33px; FLOAT: left; FONT-FACE: inherit">
    <img src=system/article.png border=0 height=15 width=13> <a href='read_news_comments.asp?id=<%=RecSet("id")%>' class="read"><font size="1"

    face="verdana" color="#000080">Read More</font></a>|<font size="1" face="verdana" color="#000080">Comments (<%=rs("totale")/RecSet("ID")%>)
    </font></div>
    </td>
    </tr>

    <%
    RecSet.Movenext
    Loop
    %>



    help pls! a buon rendere

  2. #2
    Puoi fare tutto in un'unica query, qualcosa tipo:
    codice:
    SELECT TOP 10 News.*, (SELECT Count(Pagina) FROM Commenti WHERE Pagina = News.ID) AS Totale FROM news WHERE Category ='Events' ORDER BY ID DESC
    Chi non cerca trova.

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    32
    NICE! grazie intanto, ho provato come di seguito e non fungia, dove sbaglio?


    <%

    url_DB = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("/mdb-database/database.mdb")
    Set Conn = Server.CreateObject("ADODB.Connection")
    conn.Open url_DB
    Set RecSet = Server.CreateObject("ADODB.Recordset")

    SQL = "SELECT TOP 10 News.*, (SELECT Count(Pagina) FROM Comments WHERE Pagina = News.ID) AS Totale FROM news WHERE Category ='Events' ORDER BY ID DESC"

    RecSet.Open SQL, Conn, adOpenStatic, adLockOptimistic

    If RecSet.Eof = False Then


    %>












    <TABLE width="600" cellSpacing="0" cellPadding="0" border="0">
    <tr>
    <TD vAlign=top align="right" width=74%>
    <DIV id=header_boxes style="WIDTH: 610px; border-top: #cdcdcd 1px solid; padding-left: 0px; padding-top: 10px; margin-bottom: -12px; FLOAT:

    left; background: #ffffff; FONT-SIZE: 0.9em FONT-FAMILY: Helvetica, Arial, sans-serif; FLOAT: left; COLOR: #555"><H1>Events</H1></DIV>
    <h4 class="clearfix">
    <span class="date">[img]2011/rss.png[/img] Click &

    subscribe Riders feed
    </span>
    </h4></td>
    <TD vAlign=top width=26%></td>
    </tr>
    <%
    ' VISUALIZZA LE PRIME 10 NEWS
    Do until RecSet.Eof
    %>





    <TR style="WIDTH: 620px; border-bottom: #cdcdcd 1px solid; padding-bottom: 8px; padding-top: 9px; FLOAT: left; background: #ffffff;

    FONT-SIZE: 0.90em FONT-FAMILY: Helvetica, Arial, sans-serif; FLOAT: left; COLOR: #555">

    <TD vAlign=top width=26%>
    <h4 class="clearfix">
    <span class="date">[img]system/pt.gif[/img]<%=RecSet("Date")%></span>
    </h4>
    <span class="photo"><a href='read_news_comments.asp?id=<%=RecSet("id")%>' class="photo"><img class='photo' src='<%=RecSet

    ("Preview")%>' alt='' title='' /></span>
    </a>
    </td>
    <TD vAlign=top width=74%>

    <DIV style="margin-left: 0px; margin-top: 1px; FLOAT: left; FONT-FACE: inherit">
    "><span class="title"><%=RecSet("Title")%></span>
    <span class="subtitle"><DIV style="FONT-SIZE: 1.0em; FONT-FAMILY: Helvetica, Arial, sans-serif; color: #777777"><%=RecSet("Subtitle")%

    ></div></span>
    </div>

    <DIV style="margin-left: 0px; margin-top: 33px; FLOAT: left; FONT-FACE: inherit">
    <img src=system/article.png border=0 height=15 width=13> <a href='read_news_comments.asp?id=<%=RecSet("id")%>' class="read"><font size="1"

    face="verdana" color="#000080">Read More</font></a>|<a href='read_news_comments.asp?id=<%=RecSet("id")%

    >#comments' class="read"><font size="1" face="verdana" color="#000080">Comments</a> (
    <%=RecSet("totale")%>
    )
    </font></div>

    </td>
    </tr>


    <%
    RecSet.Movenext
    Loop
    %>

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Non funziona che vuol dire?
    Qual'è l'errore?

    Roby

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    32
    ciao roby72 grazie al momento da solo

    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    /11,,050.asp, line 17

    è la linea SQL select...

    torno fra due ore che ho un collaudo all'auto, cheers!

  6. #6
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    In una delle eguaglianze della query i TIPI di campi messi in relazione non sono gli stessi.

    Roby

  7. #7
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    32
    grazie cioè sbagliato qui?

    url_DB = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("/mdb-database/database.mdb")
    Set Conn = Server.CreateObject("ADODB.Connection")
    conn.Open url_DB
    Set RecSet = Server.CreateObject("ADODB.Recordset")

    SQL = "SELECT TOP 10 News.*, (SELECT Count(Pagina) FROM Comments WHERE Pagina = News.ID) AS Totale FROM news WHERE Category ='Events' ORDER BY ID DESC"

    RecSet.Open SQL, Conn, adOpenStatic, adLockOptimistic

    If RecSet.Eof = False Then

  8. #8
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    32
    nn va, dai rega aiut!

  9. #9
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    32
    FUNZIONA QUASI! OVVERO:

    ----------------------------------------------
    ERRORE SE

    SQL = "SELECT TOP 10 News.*, (SELECT Count(pagina) FROM Comments WHERE pagina = News.ID) AS Totale FROM News WHERE Category ='Events' ORDER BY ID DESC"

    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

    ----------------------------------------------

    NUMERO CORRETTO DEI COMMENTI SE GLI DO UNA PAGINA ESATTA

    SQL = "SELECT TOP 10 News.*, (SELECT Count(pagina) FROM Comments WHERE pagina = '93') AS Totale FROM News WHERE Category ='Events' ORDER BY ID DESC"

    ----------------------------------------------

    dev'essere solo News.ID da sostituire, idee?

  10. #10
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    32
    Originariamente inviato da tas
    Puoi fare tutto in un'unica query, qualcosa tipo:
    codice:
    SELECT TOP 10 News.*, (SELECT Count(Pagina) FROM Commenti WHERE Pagina = News.ID) AS Totale FROM news WHERE Category ='Events' ORDER BY ID DESC

    TAS e Roby72 ho fatto un passo avanti:


    la query va bene se salvo il campo pagina come numerico, però non leggo più i commenti:

    esiste il modo per lasciare il database come 'testo' e aggiungere alla query un convertitore tipo:
    WHERE Pagina = convert(News.ID))

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.