Gossamer Forum
Home : General : Databases and SQL :

random display from database

Quote Reply
random display from database
Frown i have problem in randomize...as i am very lousy on it... can someone teach me on it... please...i manage to extract the information and arrange it in the way i want... i have paste my code below...

please help me....

thanx

therapySmile



<%
Dim categoryname,modcat
categoryname = Request.QueryString("categoryname")
modcat = Request.QueryString("modcat")


Dim catArr(3),catID(3)
catArr(0) = "cases"
catArr(1) = "Memory Card"
catArr(2) = "Peripherals"
catArr(3) = "Multifunction Pens"

catID(0) = "1"
catID(1) = "2"
catID(2) = "3"
catID(3) = "5"

call openConn()
Dim strHTML 'holds HTML code to write to page
Dim q 'holds the " character
q = chr(34)


Dim catname, productslist

for j=0 to ubound(catArr)
q = chr(34)
set cmd = server.CreateObject("ADODB.Command")
cmd.ActiveConnection = dbc
' cmd.CommandText = "qryProdsCategory"
' cmd.CommandType = adCmdStoredProc
' set param = cmd.CreateParameter("theCategory",adInteger,adParamInput,4)
' cmd.Parameters.Append(param)
' cmd("theCategory") = cInt(catID((j)))
' Set rs = cmd.Execute

sql = " Select products.*, products.ccategory, categories.catdescription " &_
" FROM categories INNER JOIN products ON categories.categoryID=products.ccategory " &_
" WHERE products.ccategory= " & cInt(catID((j)))

sql = sql & " ORDER BY products.stockquantity DESC, products.preorder ASC "
set rs = server.CreateObject("ADODB.Recordset")
rs.Open sql, dbc, adOpenStatic,adLockReadOnly,adCmdText

' rs.Sort="stockquantity DESC, preorder DESC"

'count number of products in each category
sql = "Select count(preOrder) as cnt FROM products WHERE ccategory="&cInt(j+1)&" and mainproduct='Yes'"
Set rscnt= Server.CreateObject ("ADODB.Recordset")
rscnt.Open sql, dbc, adOpenForwardOnly,adLockReadOnly,adCmdText
prod = rscnt("cnt")
set rscnt = nothing
%>
Quote Reply
Re: [therapy] random display from database In reply to
How are you actually trying to randomize it? You don't seem to be using RAND() Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] random display from database In reply to
Blush i missed out this part in red... it did do randomize but everytime i do refresh my item are getting lesser...

sql = " Select products.*, products.ccategory, categories.catdescription " &_
" FROM categories INNER JOIN products ON categories.categoryID=products.ccategory " &_
" WHERE products.ccategory= " & cInt(catID((j)))
sql = sql & " Order by rand()"
sql = sql & " ORDER BY products.stockquantity DESC, products.preorder ASC "
set rs = server.CreateObject("ADODB.Recordset")

'make it random
Randomize
rs.Move CLng(rs.RecordCount * Rnd())