 |
|
[ASP]
ramdom asp ช่วยหน่อยค่ะ 'Load 5 last products and randomly pick 1 set rsProducts = server. |
|
 |
|
|
 |
 |
|
<%
'Load 5 last products and randomly pick 1
set rsProducts = server.createobject("ADODB.recordset")
rsProducts.cursortype = 3
strSQL = "SELECT TOP 5 products.product_ID, product_cat_ID, newPrice, product_name, product_image FROM products INNER JOIN product_description ON products.product_ID = product_description.product_ID WHERE product_lang_ID = " & session("language_ID") & " ORDER BY products.product_ID DESC;"
rsProducts.open strSQL, adoCon
if not rsProducts.eof then
newProducts = 1
strProducts = ""
do while not rsProducts.eof
if len(strProducts) = 0 then
strProducts = rsProducts("product_ID")
else
strProducts = strProducts & ";" & rsProducts("product_ID")
end if
rsProducts.movenext
loop
rsProducts.movefirst
arrProducts = split(strProducts, ";")
if ubound(arrProducts) > 0 then
'more then 1 product --> randomize
randomize()
intNumber = Int(ubound(arrProducts) * rnd())
rsProducts.filter = "product_ID = " & arrProducts(intNumber)
end if
strImage = rsProducts("product_image")
product_ID = rsProducts("product_ID")
product_cat_id = rsProducts("product_cat_id")
product_price = Replace(rsProducts("newPrice"), ".", strServerComma)
product_name = rsProducts("product_name")
if len(strImage) > 0 then
if instr(strImage, ";") > 0 then
strImage = left(strImage, instr(strImage, ";") - 1)
end if
strImage = "products/" & strImage
else
strImage = "no_picture.jpg"
end if
end if
rsProducts.close
set rsProducts = nothing
%>
<h2>
<a href="javascript:switchBox('lastProducts');">
</a>
</h2>
<div id="lastProducts_content" class="<%=getStatus("lastProducts")%>" align="center">
<%
if newProducts = 1 then
response.write "<a href=""?mod=product&product_ID=" & product_ID & "&cat_ID=" & getLink(product_cat_id) & """>" & chr(10) & _
" <img src=""images/" & strImage & """ width=""80"" alt=""" & product_name & """ title=""" & product_name & """ /><br />" & chr(10) & _
" " & product_name & "<br />" & chr(10) & _
"</a>" & chr(10) & _
roundNumber(product_price) & strCurrency
else
response.write "There are no new products"
end if
%>
</div>
</div>
<br />
<% end if %>
นี่คือ code load สินค้า
ซึ่ง ทำการเรียก 5สินค้าล่าสุด แล้ว เลือก ใช้ 1อัน
ถ้าต้องการแก้เป็น ให้สุ่มจากสินค้าทั้งหมด แล้วเลือกใช้ 8 อัน
ต้องแก้ยีงไงค่ะ
ขอบคุณค่ะ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
13 มิ.ย. 2550 14:04:30 |
By :
ami |
View :
2395 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาตัวอย่าง มาให้ ชม
แบบนี้ คือ 10 ข้อความล้าสุด เอาไปดัดแปลงเอาน่ะ
<%
'----------------------------------------------------------------------------
' 1.ประกาศตัวแปร
Dim i
'-----------------------------------------------------------------
' 2.ติดต่อฐานข้อมูลและดึงข้อมูลจากตาราง Questions มาแสดงผล
Call ConnectDB(dbPath)
sql="select top 10 * from questions order by QNumber DESC"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorType = adOpenStatic
rs.Open sql,conn
If Not rs.EOF Then
Do While Not rs.EOF
%>
<tr>
<td height="10" width="164" valign="top" align="center">
<%If replace(left(rs("qdate"),10)," ","") = replace(formatdatetime(date,2)," ","") and rs("nanswer") = 0 then%>
<img src="images/new.gif" width="15" height="16">
<%elseif rs("nanswer") <> 0 then%>
<img src="images/oldopen.gif" width="16" height="13">
<%else%>
<img src="images/old.gif" width="15" height="13">
<%end if%>
<font face="Verdana" size="1">#<%=right("0000" & RS(0),5)%> </font> </td>
<td width="689"><font face="MS Sans Serif" size="1"><a href="aspboard_Question.asp?GID=<%=RS(0)%>" target="_blank"><%=Server.HTMLEncode(RS("QTopic"))%></a> จากคุณ <%=Server.HTMLEncode(RS("QName"))%> เมื่อวันที่ <%=rs("qdate")%> ผู้เข้าดู <font color=green><b><%=Server.HTMLEncode(RS("NView"))%></b></font> คน ผู้ตอบ <font color=red><b><%=Server.HTMLEncode(RS("NAnswer"))%></b></font> คน</font></td>
</tr>
<%
rs.MoveNext
Loop
End If
%>
</table>
</td>
</tr>
</table>
<%
rs.Close
Set rs = Nothing
Call DisconnectDB()
%>
|
 |
 |
 |
 |
Date :
25 มิ.ย. 2550 21:40:22 |
By :
monclubza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|