..:: MX Studio Fóruns ::..: Problemas no Randonize MySQL+ASP - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




ATENÇÃO

Para evitar posts desnecessários e que não influam para o andamento e desenvolvimento do fórum, clique aqui e leia todas as regras.
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problemas no Randonize MySQL+ASP

#1 User is offline   Helinho Coelho 

  • Group: Membros
  • Posts: 3
  • Joined: 28-May 11

Posted 29 June 2011 - 02:53 AM

Olá estou querendo fazer um banner rotativo com o código abaixo mas não consigo fazer funcionar em função do "Conjunto de linhas não oferecer suporte para busca regressiva". Segue abaixo o código para alguém me dizer onde estou errando.

<%
Dim RSbanner
Dim RSbanner_cmd
Dim RSbanner_numRows

Set RSbanner_cmd = Server.CreateObject ("ADODB.Command")
RSbanner_cmd.ActiveConnection = conexao
RSbanner_cmd.CommandText = "SELECT * FROM mysql.banners" 
RSbanner_cmd.Prepared = true

Set RSbanner = RSbanner_cmd.Execute
RSbanner_numRows = 0



Response.Expires = -1000

Dim rndMax,rndNumber

rndMax = CInt(RSbanner.RecordCount)
RSbanner.MoveFirst
Randomize Timer
rndNumber = Int(RND * rndMax) 
RSbanner.Move rndNumber

response.write "<a href='" & RSbanner("link") & "' target='_blank'><img border=0 width='190' height='390' src='img\banners\" & RSbanner("foto") & "'></a>"



RSbanner.Close()
Set RSbanner = Nothing
%>



O erro está apontando para a linha 23 "RSbanner.Move rndNumber". O quê devo fazer?
0

#2 User is offline   xanburzum 

  • Group: Administrador
  • Posts: 2071
  • Joined: 04-November 08

Posted 04 July 2011 - 01:43 PM

ele esta gerando algum erro ?
você também pode usar o Randomize direto na string SQL

<%
                do

                    randomize timer()
                    dim start_marker
                    start_marker = rnd() * 1000000

                    strSQL = "select offers.id, manufacturers.manufacturers,  models.model, contract_name, "
                    strSQL = strSQL & "offer_ppm as price "
                    strSQL = strSQL & "from offers "
                    strSQL = strSQL & "join manufacturers on offers.offer_manufacturer = manufacturers.id "
                    strSQL = strSQL & "join models on offers.offers_model = models.id "
                    strSQL = strSQL & "join finance_type on offers.offer_finance = finance_type.id "
                    strSQL = strSQL & "where random_number > '" & start_marker & "' and offer_finance <> '1' "
                    strSQL = strSQL & "order by random_number"

                    RecordSet.open strSQL, dbConn

                    if not(RecordSet.EOF and RecordSet.EOF) then
                        exit do
                    else
                        recordset.close
                    end if
                Loop

                %>



Você pode usar a função rand () e junto com ele utilizar o limit para restringir o nosso resultado de um registro. a função Randome é usada junto com cláusula ORDER BY para gerar registros randome.

SELECT * FROM $table_name where status='yes' ORDER BY RAND() limit 1

Para obter 10 registros aleatórios da mesma tabela.

SELECT * FROM $table_name where status='yes' ORDER BY RAND() limit 10
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic



Publicidade




1 User(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)