Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/05/2005, 21:08
Avatar de El_Metallick
El_Metallick
 
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 21 años, 6 meses
Puntos: 16
Catálogo on-line

Hola amigos... bueno en realidad este es el primer script ASP que hago solo , claro que me han ayudado con pequeñas dudas algunos de ustedes... pero bueno, lo importante es que al ser mi primer script lógicamente tieme muchas cosas que mejorar... les dejo el código a ver si a alguien le es util:

catalogo.asp
Código:
<% @ language="VBscript" %>
<% Option Explicit %>
<html>
<head>
<title>Catálogo on-line</title>
<link rel="stylesheet" type="text/css" href="estilo.css">
</head>
<body>
<%
'Declarar Variables
Dim Conn
Dim categorias_sql
Dim productos_sql
Dim rs
Dim categoria
Dim id
 
'Rescate de valores por URL
categoria = Request.Querystring("cat")
 
'Se pone una condición
if categoria = "" Then
categoria = 1
end if
 
'Instanciar y abrir la conección
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("catalogo.mdb"))
 
'Creación de la sentencia SQL correspondiente
categorias_sql="Select * From categorias"
 
'Creación del Recordset
set rs = CreateObject("ADODB.Recordset")
 
'Apertura del Recordset
rs.Open categorias_Sql, Conn
%>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="20%" valign="top">
<!-- #Include File="inc/categorias.inc" -->
</td>
<td width="80%">
<table border="0" width="60%" cellspacing="0" cellpadding="2">
	<tr>
	 <td width="10%">&nbsp;</td>
	 <td width="80%" class="text">&nbsp;&nbsp;Productos</td>
	 <td width="10%" class="text" align="right">Precio</td>
	</tr>
	<%
	'Creación de la sentencia SQL correspondiente
	productos_sql = "Select * From productos Where categoria = " & categoria & ""
 
	'Apertura dle Rescordset
	rs.Open productos_sql, Conn
 
	Do While Not rs.Eof 
	%>
	<tr>
	 <td width="10%" align="center"><a href="verdetalle.asp?cat=<% = categoria %>&pro=<% = rs("id_producto") %>"><img src="<% = rs("imagen") %>" width="50" height="50" border="0"></a></td>
	 <td width="80%">&nbsp;&nbsp;<a href="verdetalle.asp?cat=<% = categoria %>&pro=<% = rs("id_producto") %>"><% = rs("marca") %>: <% = rs("modelo") %></td>
<td width="10%" align="right">$<% = rs("precio") %></td>
	</tr>
<%
rs.MoveNext
Loop
set rs = nothing
Conn.close
set Conn=nothing
%>
</td>
</tr>
</table>
</body>
</html>
verdetalle.asp
Código:
<% @ language="VBscript" %>
<% Option Explicit %>
<html>
<head>
<title>Catálogo on-line</title>
<SCRIPT>
<!--
function displayWindow(url, width, height) 
{
var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=no,scrollbars=no,menubar=no,status=no' );
Win.resizeTo(width,height)
Win.focus();
}
//-->
</SCRIPT>
<link rel="stylesheet" type="text/css" href="estilo.css">
</head>
<body>
<%
'Declarar Variables
Dim Conn
Dim categorias_sql
Dim productos_sql
Dim rs
Dim categoria
Dim producto
 
'Rescate de valores por URL
categoria = Request.Querystring("cat")
producto = Request.Querystring("pro")
 
'Se pone una condición
if producto = "" Then
producto = 1
end if
 
'Instanciar y abrir la conección
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("catalogo.mdb"))
 
'Creación de la sentencia SQL correspondiente
categorias_sql="Select * From categorias"
 
'Creación del Recordset
set rs = CreateObject("ADODB.Recordset")
 
'Apertura del Recordset
rs.Open categorias_Sql, Conn
%>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="20%">
<!-- #Include File="inc/categorias.inc" -->
</td>
<td width="80%">
<%
'Creación de la sentencia SQL correspondiente
productos_sql = "Select * From productos Where id_producto = " & producto & ""
 
'Apertura dle Rescordset
rs.Open productos_sql, Conn
%>
<table border="0" width="60%" cellspacing="0" cellpadding="0">
	<tr>
	 <td width="90%"><% = rs("marca") %>: <% = rs("modelo") %></td>
	 <td width="10%">$<% = rs("precio") %></td>
	</tr>
	<tr>
	 <td width="90%"><% = rs("descripcion") %></td>
<td width="10%"><a href="javascript:displayWindow('imagenes.asp?pro=<% = rs("id_producto") %>',<% = rs("Ancho")+8 %>,<% = rs("Alto")+27 %>)"><img src="<% = rs("imagen") %>" alt="Pulsa para ampliar" width="50" height="50" border="0"></td>
	</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
categorias.inc
Código:
 <table border="1" width="60%" bordercolor="#DFE8FF" cellspacing="0" cellpadding="0">
	<tr>
	 <td wisth="100%" bgcolor="#DFE8FF" align="center" class="text"><b>Categorías</b></td>
	</tr>
	<tr>
	 <td width="100%">
	 <table border="0" width="100%" bgcolor="#EFEFEF" cellspacing="0" cellpadding="0">
	 <% 
	 Do While Not rs.Eof 
 
	 'Condición para que este con negrita
	 If clng(categoria) = rs("id_categoria") Then
	 %>
	<tr>
		<td width="100%"><b><a href="catalogo.asp?cat=<% = rs("id_categoria") %>"><% = rs("nombre_categoria") %></a></b> (<% = rs("total_productos") %>)</td>
	 </tr>
	<% else %>
	<tr>
	 <td width="100%"><a href="catalogo.asp?cat=<% = rs("id_categoria") %>"><% = rs("nombre_categoria") %></a> (<% = rs("total_productos") %>)</td>
	 </tr>
	<%
	end if
 
	rs.MoveNext
	Loop
	rs.close
	%>
	 </table>
	 </td>
	</tr>
</table>
imagenes.asp
Código:
<html>
<head>
<title>Ver una imagen de la galeria</title>
</head>
<body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0>
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("catalogo.mdb"))
strSQL = "Select * from productos Where id_producto = " & Request.QueryString("pro")
Set RS = Conn.Execute(strSQL)
Response.Write "<img src=""" & rs("imagen") & """ border=""0"" width=""" & rs("ancho") & """ height=""" & rs("alto") & """>"
 
Conn.Close
Set Conn = Nothing
%>
</body>
</html>
Y por último la estructura de las tablas de la BD

tabla categorias:

id_categoria (autonumerico)
nombre_categoria (texto)
total_productos (numerico)

tabla productos:
id_producto (autonumerico)
categoria (numerico)
imagen (texto)
ancho (numerico) --->ancho de la imagen
alto (numerico) --->alto de la imagen
marca (texto)
modelo (texto)
descripcion (texto)
precio (texto)

Bueno espero que les sea de utilidad y que bueno... ojala que me den sugerencias de como mejorarlo.... bueno saludos y gracias a todos los que me ayudaron con pequeñas trabas.....
__________________
Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!!

Última edición por El_Metallick; 12/05/2005 a las 09:00