Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Luka13

Problema com SELECT e ordem

Recommended Posts

Em uma página quero exibir 2 notícias de um mesmo banco, uma do lado da outra.

Fiz 2 Recordsets. Gostaria de exibir a notícia "X" e ao lado a notícia anterior a ela ("X-1").

Veja o código:

 

<%
Dim Noticias
Dim Noticias_cmd
Dim Noticias_numRows

Set Noticias_cmd = Server.CreateObject ("ADODB.Command")
Noticias_cmd.ActiveConnection = MM_Noticias_STRING
Noticias_cmd.CommandText = "SELECT * FROM Noticias ORDER BY ID DESC"  
Noticias_cmd.Prepared = true

Set Noticias = Noticias_cmd.Execute
Noticias_numRows = 0
%>
<%
Dim Noticias2
Dim Noticias2_cmd
Dim Noticias2_numRows

Set Noticias2_cmd = Server.CreateObject ("ADODB.Command")
Noticias2_cmd.ActiveConnection = MM_Noticias_STRING
Noticias2_cmd.CommandText = "SELECT * FROM Noticias ORDER BY ID DESC" 
Noticias2_cmd.Prepared = true

Set Noticias2 = Noticias2_cmd.Execute
Noticias2_numRows = 0
%>

 

Devo trabalhar no SELECT com a ID ou com a DATA? E como fazer isso?

Compartilhar este post


Link para o post
Compartilhar em outros sites

usa uma paginação ou um ticker com JQuery

Compartilhar este post


Link para o post
Compartilhar em outros sites

olha este exemplo, um scrolling ticker de notícias

 

<%
Dim ID		
ID = Request.QueryString("ID") 'ID matches the Entry_ID for the news item in the database
'The following lines of code connect to the database and create the recordset.
Dim conCurrent
Dim rstCurrent				
Set conCurrent = Server.CreateObject("ADODB.Connection")
Set rstCurrent = Server.CreateObject("ADODB.recordset")
conCurrent.connectionString = "driver={Microsoft Access Driver (*.mdb)};" & _
"dbq=c:\inetpub\wwwroot\news.mdb"
conCurrent.Open
strSQL="SELECT * FROM news WHERE Entry_ID=" & ID  'We use the ID here to select the correct
Set rstCurrent = conCurrent.Execute(strSQL)	      'news item

%>
<html>
<head>
<title>News Detail Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Authors" content="Brent Wenson">
</head>

<body bgcolor="tan" text="#000000">
<CENTER>
 <H1>ASP News Ticker!</H1>
 <hr>
</CENTER>
<%
' The next lines get the info from the current news record and write them to the HTML Page
%>
<P><i><%=rstCurrent("Entry_Date")%></i> - <B><%=rstCurrent("Title")%></B></P><BR>
<P><%=rstCurrent("Text")%></P>
<P> </P>
<P><a href="newsfront.asp">Return to the Ticker!</a></P>

</body>
</html>

<%
conCurrent.close
set conCurrent = Nothing
%>

 

<%
' The following is the code for the scrolling news ticker.  This will only work on a IIS server and IE browsers.  Netscape users will still see the news, but it will not scroll.

Dim sTxt, iSpeed, iTop, iLeft, iWidth, iHeight, sHtml1, sHtml2, sHtml4, strSQL,sMarquee
Dim conCurrent
Dim rstCurrent				
Set conCurrent = CreateObject("ADODB.Connection")
Set rstCurrent = Server.CreateObject("ADODB.Recordset")
conCurrent.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
 "DBQ=c:\inetpub\wwwroot\news.mdb"
strSQL = "SELECT * FROM news ORDER BY Entry_Date DESC"
Set rstCurrent = conCurrent.Execute(strSQL)
sHtml1 = "<P><CENTER><FONT SIZE='-1' COLOR='Black'>"
sHtml2 = "<A HREF='newsdetail.asp?ID="
sHtml3 = "'>"
sHtml4 = "</A></FONT></CENTER></P>"
sTxt = ""
rstCurrent.movefirst
do while not rstCurrent.eof	'I used variables here to try and reduce this long assignment
	sTxt = sTxt & sHtml1 & rstCurrent("Entry_Date") & " - " & sHtml2 & _
	 rstCurrent("Entry_ID") & sHtml3 & rstCurrent("Title") & sHtml4
	rstCurrent.movenext
loop
iSpeed = 40 	' Speed of Marquee (higher = slower)
  	iTop = 0		' Y Location Within Object
  	iLeft = 0		' X Location""""
  	iWidth = 125	' Width 
  	iHeight = 167	' Height
  	'Insert marquee into objects innerHtml Property (in this Case a table cell)
sMarquee="<MARQUEE onmouseover='this.stop();' " & _
 "onmouseout='this.start();'direction='up' scrollamount='1' " & _
 "scrolldelay='" & iSpeed & "' top='" & iTop & "' left='" & iLeft & _
 "' width='" & iWidth & "' height='" & iHeight & "'>" & sTxt & "</MARQUEE>"

  	conCurrent.close		'Don't forget to clean-up!
set conCurrent = Nothing
   %>
<html>
<head>
<title>News Front Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Authors" content="Brent Wenson">
</head>

<body bgcolor="tan" text="#000000">
<CENTER><H1>ASP News Ticker!</H1></CENTER>
<P> </P>
           <table style="border-left: 1 solid #000000;border-right: 1 solid #D0D5DF;border-																		top: 1 solid #000000; border-bottom: 1 solid #D0D5DF" bgcolor=white width=125 height=167 cellpadding="2" cellspacing="0" align="center">
             <tr> 
               <td width="iWidth" height="166" bgcolor="#CCCCCC" id="tDisplay" bordercolor="#3333FF"> 
                 <%=sMarquee%> </td>
             </tr>
           </table>

</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.