Visualizzazione dei risultati da 1 a 10 su 10
  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    34

    Evitare il loop in un sistema di news

    Buongiorno.

    Ho questo script che mi estrapola i dati contenuti in un database:

    codice:
    
    
    <%
    if request("dtype") = "" then dtype = dtype else dtype = request("dtype")
    if catid = "" then catid = request("catid")
    if recid = "" then recid = request("recid")
    if weburl = "" then weburl = Request.ServerVariables("url") 
    if dtype = "2" then
    	if catid = "" then catid = 1
    	Response.Write DisplayData(2, catid, "", weburl)
    	nDisplayRecs = 2
    end if
    
    Function DisplayData(dtype, catid, recid, filename)
    
    	tablestyle = """BORDER-RIGHT: #f2f0f4 0px solid; BORDER-TOP: #f2f0f4 0px solid; BORDER-LEFT: #f2f0f4 0px solid; BORDER-BOTTOM: #f2f0f4 0px solid"""
    	headerfontsize = "2"
    	headerfontcolor = "white"
    	fontface = "Arial"
    	fontcolor = "black"
    	
    
    	
    	set dataconn =Server.CreateObject("ADODB.Connection")
    	dataconn.ConnectionString = xDb_Conn_Str
    	dataconn.open
    
    		Select case dtype
    
    		case 2
    			
    			query = "select catname from NMCattbl where catid = "& catid
    			set rs = dataconn.Execute(query)
    				if not rs.eof then
    					Response.Write "
    <TABLE WIDTH=100% align=center valign=top style="&tablestyle&" BORDER=0 CELLSPACING=0 CELLPADDING=4>"
    					Response.Write "<tr><td colspan=2 width=100% valign=top></td></tr>"
    					query1 = "select newsid,newsname,newsdateadded,newsdescription,newsdoc1name from NMNewstbl where catid = "& catid &" and activated = "& true & " and newsexpiry > #"& date() &"# order by newsdateadded desc"
    					set rs1 = dataconn.Execute(query1)
    						if rs1.eof then
    							Response.Write "<tr><td colspan=2 width=100% valign=top><FONT face="&fontface&" size="&fontsize&" color="&fontcolor&">Currently there are no News Articles in this Section</font></td></tr>"
    						else
    							do until rs1.eof
    								Response.Write "<tr><td width=100% valign=top><FONT face="&fontface&" size="&fontsize&" color="&fontcolor&">"
    								if rs1(4) <> "" then 
    									Response.Write "<center>[img][/img]</center>"
    								end if
    								Response.Write ""&rs1(1)&" "&rs1(2)&"
    "&rs1(3)&"
    Leggi tutto</font></td></tr>"
    							rs1.movenext
    							loop
    						end if
    					rs1.close
    					set rs1 = nothing
    					Response.Write "</table>"
    				else
    					Response.Write "
    <TABLE WIDTH=100% align=center valign=top style="&tablestyle&" BORDER=0 CELLSPACING=0 CELLPADDING=4>"
    					Response.Write "<tr><td width=100% bgcolor="& headerbgcolor&" valign=top><FONT face="&fontface&" size="& headerfontsize&" color="& headerfontcolor&">No Category found with this Id.</font></td></tr>"
    					Response.Write "<tr><td width=100% valign=top><FONT face="&fontface&" size="&fontsize&" color="&fontcolor&">News Articles not found.</font></td></tr>"
    					Response.Write "</table>"
    				end if
    			rs.close
    			set rs = nothing
    
    		case else
    		End select
    
    	dataconn.Close
    	set dataconn = nothing
    
    End Function%>
    Lo script fa vedere tutte le news, mentre io vorrei farne visualizzare solo le prime 5.

    Vorrei sapere cosa e dove devo modificare il codice.

    Ciao e grazie.

  2. #2
    SELECT TOP 5 ....

    laddove ti serve

  3. #3
    codice:
    						if rs1.eof then
    							Response.Write "<tr><td colspan=2 width=100% valign=top><FONT face="&fontface&" size="&fontsize&" color="&fontcolor&">Currently there are no News Articles in this Section</font></td></tr>"
    						else
    							cnt = 1
    							do until rs1.eof
    								Response.Write "<tr><td width=100% valign=top><FONT face="&fontface&" size="&fontsize&" color="&fontcolor&">"
    								if rs1(4) <> "" then 
    									Response.Write "<center>[img][/img]</center>"
    								end if
    								Response.Write ""&rs1(1)&" "&rs1(2)&"
    "&rs1(3)&"
    Leggi tutto</font></td></tr>"
    							rs1.movenext
    							cnt = cnt + 1
    							if cnt = 6 then exit do
    							loop
    						end if

  4. #4
    dome', la tua idea è quella di uscire dal loop quando ne hai stampate 5?

    cioè, ti carichi in pancia dodici milioni di records per stamparne solo qualcuno? la TOP x allora a cosa serve?

  5. #5
    Può anche fare una TOP 5 assiema al mio esempio.

  6. #6
    Originariamente inviato da Domenix
    Può anche fare una TOP 5 assiema al mio esempio.
    il famoso grasso che cola


  7. #7
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    34
    Ciao

    Intanto grazie.

    Il fatto è che questo script va in homepage, quindi devo far vedere solo alcuni dati, non tutti.

  8. #8
    Originariamente inviato da optime
    il famoso grasso che cola

    E io so quoco. Mika programmatorre.

  9. #9
    mimmo, sei sempre tu.... cambia il nick, ma non il cuoco

  10. #10
    Originariamente inviato da optime
    mimmo, sei sempre tu.... cambia il nick, ma non il cuoco
    Errì! E Daje...

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.