random number

I

isaac2004

hi how would you go changing a random number generated into a item
drawn from a database with SQL
 
E

Evertjan.

isaac2004 wrote on 11 feb 2006 in microsoft.public.inetserver.asp.general:
hi how would you go changing a random number generated into a item
drawn from a database with SQL

You mean having a variable filled with a random number,
and then filling that variable with the value of a database field?

It wouldn't be random then?
 
I

isaac2004

no having a random item be generated to a page. the items are on the
database and using SQL to generate a random item name using the
Randomize function
 
E

Evertjan.

isaac2004 wrote on 12 feb 2006 in microsoft.public.inetserver.asp.general:
no having a random item be generated to a page. the items are on the
database and using SQL to generate a random item name using the
Randomize function

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsreply/>

==============================

I still do not understand what you are asking, Isaak

What is a "generated random item"?
And you have no[t] genreated it to(?) a page?

Tell us about the type and content of your databse, and show us the
relevand ASP code, you have come up with so far.
 
I

isaac2004

my database consists of two tables one vendors and other Items, i want
to have a page on my site that when viewed a random item is displayed
such as


Today we have a sale on Tight Fit Denim jeans by Polo
----------------------------------->
this is the random item
the item is randomly generated by a randomizer that picks the item name
out of the database and displays the item name, item type, and price

i use this code

randomize
intItemID = Int(22* rnd(1)) +1
for the random but i dont know how to convert the random number into
the item type. this is for my asp class, if you want a working example,
go here

http://yorktown.cbe.wwu.edu/sandvig/mis314/assignments/SQL/RandomItem.asp

thanks for the help
 
E

Evertjan.

isaac2004 wrote on 12 feb 2006 in microsoft.public.inetserver.asp.general:
my database consists of two tables

If you persist neglecting usenet netiquette by not quoting,
even when politely asked,
I will stop anwering you on your topic.
 
I

isaac2004

If you persist neglecting usenet netiquette by not quoting,
even when politely asked,
I will stop anwering you on your topic.

sorry i forgot
I still do not understand what you are asking, Isaak

What is a "generated random item"?
And you have no[t] genreated it to(?) a page?

Tell us about the type and content of your databse, and show us the
relevand ASP code, you have come up with so far.

my database consists of two tables one vendors and other Items, i want
to have a page on my site that when viewed a random item is displayed
such as

Today we have a sale on Tight Fit Denim jeans by Polo
----------------------------------->
this is the random item
the item is randomly generated by a randomizer that picks the item name

out of the database and displays the item name, item type, and price


i use this code


randomize
intItemID = Int(22* rnd(1)) +1
for the random but i dont know how to convert the random number into
the item type. this is for my asp class, if you want a working example,

go here


http://yorktown.cbe.wwu.edu/sandvig/mis314/assignments/SQL/RandomItem...



thanks for the help
 
E

Evertjan.

isaac2004 wrote on 12 feb 2006 in microsoft.public.inetserver.asp.general:
randomize
intItemID = Int(22* rnd(1)) +1
for the random but i dont know how to convert the random number into
the item type. this is for my asp class, if you want a working example,

SQL = "SELECT * from tblX WHERE ID = " & intItemID
 
I

isaac2004

SQL = "SELECT * from tblX WHERE ID = " & intItemID

doesnt this code just source from the databse but not put it through a
random number generator
 
E

Evertjan.

isaac2004 wrote on 12 feb 2006 in microsoft.public.inetserver.asp.general:
doesnt this code just source from the databse but not put it through a
random number generator

No, you came up with the random number generator, remember:

so intItemID was defined.

Please do not use inconclusive terminology like "just source from"

Better show us the code you have so far.
 
I

isaac2004

Better show us the code you have so far.

here is the code

<% Option Explicit %>
<!--#include file="DatabaseConnect.asp"-->
<!--#include virtual="/06Winter/levini/database/adovbs.inc"-->
<html>
<head>
<title>Clothier Database</title>
</head>

<body>
<center>
<h3>Query the Clothier Database</h3><hr>



<% Dim intItemID, strSQL, objRS, sngTax, sngDiff
randomize
intItemID = Int(22* rnd(1)) +1



strSQL = "SELECT Items.ItemName, Items.ItemType,
Items.ItemPriceBuy, Vendors.VendorName " & _
"FROM Items, Vendors"

response.write(strSQL)
Set objRS = Server.CreateObject ("ADODB.Recordset")
objRS.Open strSQL, objConn


response.write"<center><font color = red>Today's special item is the "
& intItemID & " " & objRS("ItemType") & " " & objRS("VendorName") &
".</font>"


function PriceIt()

If IsNumeric(intItemID) then
sngTax = formatcurrency(objRS("ItemPriceBuy") * 1.8)
sngDiff = formatcurrencty(sngTax - objRs("ItemPriceBuy"))
end if

response.write"<center><font color = red>Today's special item is the "
& objRS("ItemID") & objRS("ItemType") & objRS("VendorName") &
".</font>"
response.write"<center><font color = green>Suggested Retail: " & sngTax
& "</font><br>"
response.write"<center><font color = green>Today only: " &
objRS("ItemPriceBuy") & "</font><br>"
response.write"<center><font color = green>Your Savings: " & sngDiff &
"</font><br>"

end function
%>
<p align='center'><a href='RandomItem.asp'>New Random Item</a></p>
</body>

</html>

a working version of this concept is
http://yorktown.cbe.wwu.edu/sandvig/mis314/assignments/SQL/RandomItem
 
E

Evertjan.

isaac2004 wrote on 13 feb 2006 in microsoft.public.inetserver.asp.general:
Better show us the code you have so far.

here is the code
[..]

<% Dim intItemID, strSQL, objRS, sngTax, sngDiff
randomize
intItemID = Int(22* rnd(1)) +1



strSQL = "SELECT Items.ItemName, Items.ItemType,
Items.ItemPriceBuy, Vendors.VendorName " & _
"FROM Items, Vendors"

response.write(strSQL)

Why not introduce a WHERE clause as I showed you?
Nouw you select the whole database!

Set objRS = Server.CreateObject ("ADODB.Recordset")
objRS.Open strSQL, objConn

Why do you use a recordset?

better use:

set CONNECT = server.CreateObject("ADODB.Connection")
CONNECT.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _
Server.MapPath("/dir/file.mdb") & ";"
set mDATA=CONNECT.Execute(SQL)

What is "objConn" related to?
response.write"<center><font color = red>Today's special item is the "
& intItemID & " " & objRS("ItemType") & " " & objRS("VendorName") &
".</font>"

You did not select the item [with a WHERE clause].
function PriceIt()

You do not call this function at all!!!

If IsNumeric(intItemID) then
sngTax = formatcurrency(objRS("ItemPriceBuy") * 1.8)
sngDiff = formatcurrencty(sngTax - objRs("ItemPriceBuy"))
end if

response.write"<center><font color = red>Today's special item is the "
& objRS("ItemID") & objRS("ItemType") & objRS("VendorName") &
".</font>"
response.write"<center><font color = green>Suggested Retail: " & sngTax
& "</font><br>"
response.write"<center><font color = green>Today only: " &
objRS("ItemPriceBuy") & "</font><br>"
response.write"<center><font color = green>Your Savings: " & sngDiff &
"</font><br>"

end function
%>
<p align='center'><a href='RandomItem.asp'>New Random Item</a></p>
</body>

</html>

a working version of this concept is
http://yorktown.cbe.wwu.edu/sandvig/mis314/assignments/SQL/RandomItem

No, it is not, "The page cannot be found"

I would suggest building a test page with the advice above, just showing
your basic need, and in working condition eor with the errors pointed at.

Is this really code you made, or are you patching code cuttings you do not
understand?
 
I

isaac2004

got it to work heres the code

<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include file="DatabaseConnect.asp"-->
<!--#include virtual="06winter/levini/database/adovbs.inc"-->
<% Dim strSQL, objRS, intItemID, strItemName, strItemType,
strVendorName, curItemPriceBuy, curDiscPrice
randomize
intItemID = Int(22* rnd(1)) +1

strSQL = "SELECT Items.ItemName, Items.ItemType, Items.ItemPriceBuy,
Vendors.VendorName, Items.ItemID " & _
"FROM Vendors INNER JOIN Items ON Vendors.VendorID =
Items.VendorID " & _
"WHERE (((Items.ItemID)=" & intItemID & "));"

Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.open strSQL, objConn
strItemName = objRS("ItemName")
strItemType = objRS("ItemType")
strVendorName = objRS("VendorName")
curItemPriceBuy = FormatCurrency(objRS("ItemPriceBuy"))
curDiscPrice = FormatCurrency((objRS("ItemPriceBuy")*1.8))

objRS.close
Set objRS = nothing
objConn.close
Set objRS = nothing
%>
<html>
<head>
<title>Clothier Database</title>
</head>
<body>
<center>
<h1>Clothier Database</h1>
&nbsp;
<hr>
<p><font size="3" face="Comic Sans MS" color="#FF0000">
Today's special item is the <% =strItemName%></font>
<font size="3" face="Comic Sans MS" color="#FF0000"><%
=strItemType %> by <% =strVendorName %>.
</font>
</p>
<table border="0" cellpadding="5">
<tr>
<td>
<font face="Comic Sans MS" size="3" color="#008080">
Suggested Retail:
</td>
<td>
<strike><font face="Comic Sans MS" color="#0000FF">
<% =curDiscPrice %></font></strike>
</td>
</tr>
<tr>
<td>
<font face="Comic Sans MS" size="3" color="#008080">
Today only:
</td>
<td>
<font face="Comic Sans MS" color="#0000FF">
<% =curItemPriceBuy %> </font>
</td>
</tr>
<tr>
<td>
<font face="Comic Sans MS" size="3" color="#008080">
Your Savings:
</td>
<td>
<font face="Comic Sans MS" color="#0000FF">
<% =FormatCurrency((curDiscPrice - curItemPriceBuy))
%></font>
</td>
</tr>
</table>
<br>
<p align='center'><a href='RandomItem.asp'>New Random Item</a></p>
</center>
</body>
</html>

thank you for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top