Dear tek tips gurus,
I have a page here which displays a random record each time. However, I only want it to display the record if it meets this criteria: Specialtag = 1 (Specialtag is a columm in my database). I only want to show a special product, not a normal product, this is why. So look at my code below and see what I can do! Thanks (Basically, i want to display a random record of just the special product)
<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim lowestnumber, highestnumber, randomnumber, altrandomnumber
Dim ConnectionString as String = "server=x;user id=x;pwd=x;database=x"
RANDOMIZE
LowestNumber = 4
HighestNumber = 39
RandomNumber = Int((HighestNumber-LowestNumber+1)*Rnd+LowestNumber)
Dim CommandText As String = "SELECT * FROM products WHERE idproduct = " & randomnumber
Dim myConnection As New SqlConnection(ConnectionString)
Dim objdr as SQLDataReader
Dim myCommand As New SqlCommand(CommandText, myConnection)
myConnection.open()
objdr=myCommand.ExecuteReader(system.data.CommandBehavior.CloseConnection)
objdr.read()
if objdr("specialtag") = "0"
(OR should it be WHILE ???)
'(i'm trying to say if it is NOT a special product, randomize again until you find the criteria of specialtag = 1!!)
randomize?
end if
'the code below puts teh data on display!
image1.imageurl = objdr("smallImageURL")
description.text = objdr("description")
listprice.text = "$" & objdr("listprice")
price.text = objdr("price")
descriptionlong.text = objdr("descriptionLong")
hyperlink1.navigateurl = "estore/scripts/prodview.asp?idproduct=" & objdr("idproduct")
hyperlink1.text = objdr("description")
objdr.close()
myConnection.close()
End Sub
</script>
<html>
<head>
<link href="icw.css" type="text/css" rel="stylesheet" />
</head>
<body>
<table>
<tbody>
<tr>
<td valign="top">
<span class="icwsmall">
<p align="center">
<asp:Image id="Image1" runat="server"></asp:Image>
<br>
<asp:HyperLink id="hyperlink1" Runat="server"></asp:HyperLink>
<p align="center">
<img border="0" src="images/ssale.jpg" width="193" height="27"><br>
</a>
<br />
<asp:Label ID="description" Runat="server"></asp:Label></a></font>
<br />
<asp:Label ID="special" Runat="server"></asp:Label><br>
List Price: <asp:Label ID="listprice" Runat="server"></asp:Label>
<br />
Our Price: <asp:Label ID="price" Runat="server"></asp:Label>
<br />
<asp:Label ID="descriptionlong" Runat="server"></asp:Label>
</td>
<td>
</td>
<tbody>
</tbody>
</tbody>
</table>
</body>
</html>
I have a page here which displays a random record each time. However, I only want it to display the record if it meets this criteria: Specialtag = 1 (Specialtag is a columm in my database). I only want to show a special product, not a normal product, this is why. So look at my code below and see what I can do! Thanks (Basically, i want to display a random record of just the special product)
<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim lowestnumber, highestnumber, randomnumber, altrandomnumber
Dim ConnectionString as String = "server=x;user id=x;pwd=x;database=x"
RANDOMIZE
LowestNumber = 4
HighestNumber = 39
RandomNumber = Int((HighestNumber-LowestNumber+1)*Rnd+LowestNumber)
Dim CommandText As String = "SELECT * FROM products WHERE idproduct = " & randomnumber
Dim myConnection As New SqlConnection(ConnectionString)
Dim objdr as SQLDataReader
Dim myCommand As New SqlCommand(CommandText, myConnection)
myConnection.open()
objdr=myCommand.ExecuteReader(system.data.CommandBehavior.CloseConnection)
objdr.read()
if objdr("specialtag") = "0"
(OR should it be WHILE ???)
'(i'm trying to say if it is NOT a special product, randomize again until you find the criteria of specialtag = 1!!)
randomize?
end if
'the code below puts teh data on display!
image1.imageurl = objdr("smallImageURL")
description.text = objdr("description")
listprice.text = "$" & objdr("listprice")
price.text = objdr("price")
descriptionlong.text = objdr("descriptionLong")
hyperlink1.navigateurl = "estore/scripts/prodview.asp?idproduct=" & objdr("idproduct")
hyperlink1.text = objdr("description")
objdr.close()
myConnection.close()
End Sub
</script>
<html>
<head>
<link href="icw.css" type="text/css" rel="stylesheet" />
</head>
<body>
<table>
<tbody>
<tr>
<td valign="top">
<span class="icwsmall">
<p align="center">
<asp:Image id="Image1" runat="server"></asp:Image>
<br>
<asp:HyperLink id="hyperlink1" Runat="server"></asp:HyperLink>
<p align="center">
<img border="0" src="images/ssale.jpg" width="193" height="27"><br>
</a>
<br />
<asp:Label ID="description" Runat="server"></asp:Label></a></font>
<br />
<asp:Label ID="special" Runat="server"></asp:Label><br>
List Price: <asp:Label ID="listprice" Runat="server"></asp:Label>
<br />
Our Price: <asp:Label ID="price" Runat="server"></asp:Label>
<br />
<asp:Label ID="descriptionlong" Runat="server"></asp:Label>
</td>
<td>
</td>
<tbody>
</tbody>
</tbody>
</table>
</body>
</html>