random number

Discussion in 'ASP General' started by isaac2004, Feb 11, 2006.

  1. isaac2004

    isaac2004 Guest

    hi how would you go changing a random number generated into a item
    drawn from a database with SQL
     
    isaac2004, Feb 11, 2006
    #1
    1. Advertising

  2. isaac2004

    Evertjan. Guest

    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?


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 11, 2006
    #2
    1. Advertising

  3. isaac2004

    isaac2004 Guest

    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
     
    isaac2004, Feb 11, 2006
    #3
  4. isaac2004

    Evertjan. Guest

    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.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 11, 2006
    #4
  5. isaac2004

    isaac2004 Guest

    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
     
    isaac2004, Feb 12, 2006
    #5
  6. isaac2004

    Evertjan. Guest

    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.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 12, 2006
    #6
  7. isaac2004

    isaac2004 Guest

    >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
     
    isaac2004, Feb 12, 2006
    #7
  8. isaac2004

    Evertjan. Guest

    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

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 12, 2006
    #8
  9. isaac2004

    isaac2004 Guest

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

    doesnt this code just source from the databse but not put it through a
    random number generator
     
    isaac2004, Feb 12, 2006
    #9
  10. isaac2004

    Evertjan. Guest

    isaac2004 wrote on 12 feb 2006 in microsoft.public.inetserver.asp.general:

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

    >
    > 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:

    >> randomize
    >> intItemID = Int(22* rnd(1)) +1


    so intItemID was defined.

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

    Better show us the code you have so far.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 12, 2006
    #10
  11. isaac2004

    isaac2004 Guest

    >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
     
    isaac2004, Feb 12, 2006
    #11
  12. isaac2004

    Evertjan. Guest

    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?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 12, 2006
    #12
  13. isaac2004

    isaac2004 Guest

    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
     
    isaac2004, Feb 13, 2006
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darren Clark

    Random NOt random?

    Darren Clark, Jun 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    486
    mikeb
    Jun 24, 2004
  2. xeys_00
    Replies:
    12
    Views:
    869
    Jonathan Arnold
    Apr 11, 2005
  3. globalrev
    Replies:
    4
    Views:
    812
    Gabriel Genellina
    Apr 20, 2008
  4. Alex Untitled
    Replies:
    11
    Views:
    685
    Giampiero Zanchi
    Nov 16, 2009
  5. VK
    Replies:
    15
    Views:
    1,322
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page