Código:
<a href="http://www.almaluz.com"><Img src="http://www.almaluz.com/banners/B_almaluz.gif"></a> <% Option Explicit randomize Dim elementos, con, rs, sql, matrizseleccionados, maximo, salto, valor, referencia, nombre, precio, foto, i elementos= 4 Set con=Server.CreateObject("ADODB.connection") Set rs=Server.CreateObject("ADODB.RecordSet") sql= "SELECT referencia, nombre, pvp5, foto FROM articulo WHERE enportada=-1 ;" ' filtramos la tabla seleccionando ' los productos a mostrar con.Open "catalogo" ' abre la conexion usando DSN rs.Open sql, con IF NOT rs.EOF THEN matrizseleccionados = rs.GetRows() rs.Close con.Close Set rs=Nothing Set con=Nothing ' Aqui empezamos el codigo para mostrar de forma aleatoria de 4 en 4 maximo = UBOUND (matrizseleccionados, 2)+1 ' el nº maximo de registros + 1 porque el primer registro es el 0 salto = maximo / elementos ' dividimos el total de elementos entre los elementos a mostrar cada vez IF maximo <= elementos THEN salto = 1 ' si el numero resultante es menor o igual del numero de elementos a mostrar ' establecemos este valor a 1 %> <html> <head> <title>Muestra de forma aleatoria </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <% FOR i=0 TO maximo-1 STEP salto valor = RND * (salto-1) ' establece un valor aleatorio referencia= matrizseleccionados (0,i+valor) ' asigna la primera columna (referencia) y el nº registro aleatorio a la variable nombre=matrizseleccionados (1,i+valor) precio=matrizseleccionados (2,i+valor) foto=matrizseleccionados (3,i+valor) %> <table> <tr> <td><% IF TRIM(foto)<> "" THEN %> <img src="imagenes/<%= foto %>"> <% END IF %> </td> <td> <%= referencia %> </td> <td> <%= precio %> </td> <td> <%= nombre %> </td> </tr> </table> <% NEXT END IF %> </body> </html>