超簡單flash+asp+access計數器

來源:互聯網
上載者:User
access|asp+|計數器

  雖然計數器不一定要用資料庫,不過我這個計數器真是非常非常地簡單 

  大部分是受了guoy_8186的啟發,他的投票教程真的非常不錯。

  Flash代碼:

var count = new LoadVars(); //建立一個loadVars對象 
count.load("你的路徑/write.asp", count); //讀取asp檔案 
count.onLoad = function(success) { 
 if (success) { 
  visits = count.total; 
 } //上面是判斷是否讀取完畢,完成後把讀到的變數賦予情境中的變數 
};     asp代碼: 
<% 
dim rs 
dim sql 
dim conn ‘定義變數 
set rs=server.createobject("adodb.recordset") ’建立資料集對象 
conn = "DBQ=" + server.mappath("counter.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" ‘資料庫連接語句,預設是你的空間根目錄,如果資料庫檔案前面有檔案夾路徑要加上去 
sql="update count set num=num+1 where id=1" ’給num這個值加上1的語句 
rs.open sql,conn,1,1 ‘執行寫入  
sql2="select * from count where id=1" ’讀取的語句 
rs.open sql2,conn,1,1 ‘執行讀取 
if not rs.eof then 
total=rs("num") ’把資料庫裡的值賦予一個變數 
response.write"&total="&total&"&" ’把資料寫成flash可以讀取的形式 
else 
end if 
set rs=nothing 
set conn=nothing 
%> 

  資料庫用access,建一個資料庫叫counter,在裡面建一個新表叫count,表裡面只需要建立兩個欄位,一個叫id,類型選自動編號,設定為主鍵;另一個叫num,類型是數字,這個欄位就是儲存資料的地方。 

  這樣就OK了!以後每次開啟這個flash檔案就會在資料庫裡增加1,因為讀取到flash裡面是個變數,你可以隨心所欲地處理它。附上原始碼下載:點擊這裡下載源檔案



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.