主题:  动网论坛代码之-显示用户星座

听雪堂主

职务:普通成员
等级:1
金币:1.0
发贴:286
注册:2002/3/15 11:35:27
#12003/8/15 12:24:13

  用过动网论坛的朋友都知道,查看贴子时,用户信息那一块有一个小图标,显示的是发贴用户的星座。让每一个用户在注册时填写好自己的星座是不现实的,大家都是懒人,能填上生日就不错了,幸好,我们可以通过生日来计算出星座来,先看下面这一段程序,这可以从动网论坛的程序中提出来的:

<%
function astro(birthday)
on error resume next
dim birth,birthmonth
birth=day(birthday)
birthmonth=month(birthday)
select case birthmonth
case 1
    if birth>=21 then
    astro="水瓶座"&birth&""
    else
    astro="魔羯座"&birth&""
    end if
    case 2
    if birth>=20 then
    astro="双鱼座"&birth&""
    else
    astro="水瓶座"&birth&""
    end if
      case 3
    if birth>=21 then
    astro="白羊座"&birth&""
    else
    astro="双鱼座"&birth&""
    end if
    case 4
    if birth>=21 then
    astro="金牛座"&birth&""
    else
    astro="白羊座"&birth&""
    end if
    case 5
    if birth>=22 then
    astro="双子座"&birth&""
    else
    astro="金牛座"&birth&""
    end if
    case 6
    if birth>=22 then
    astro="巨蟹座"&birth&""
    else
    astro="双子座"&birth&""
    end if
    case 7
    if birth>=23 then
    astro="狮子座"&birth&""
    else
    astro="巨蟹座"&birth&""
    end if
    case 8
    if birthday>=24 then
    astro="处女座"&birth&""
    else
    astro="狮子座"&birth&""
    end if
    case 9
    if birth>=24 then
    astro="天秤座"&birth&""
    else
    astro="处女座"&birth&""
    end if
    case 10
    if birth>=24 then
    astro="天蝎座"&birth&""
    else
    astro="天秤座"&birth&""
    end if
    case 11
    if birth>=23 then
    astro="射手座"&birth&""
    else
    astro="天蝎座"&birth&""
    end if
    case 12
    if birth>=22 then
    astro="魔羯座"&birth&""
    else
    astro="射手座"&birth&""
    end if
    case else
    astro=""
    end select
end function
%>

  这一段程序该怎么用呢?呵呵,先把它复制到你的站点中去,取名birthday.asp,然后将其包含进你想显示用户名的页面中,,现在假使你的用户记录集为Reuserlist,而用户生日保存在birthday字段中,那么,在想显示星座图片的地方加入如下代码就行了:

<% if Reuserlist.Fields.Item("birthday").value<>"" then
userbirth=astro(Reuserlist.Fields.Item("birthday").value)
response.write ""&userbirth&""
end if %>

在动网论坛里把star那个文件夹复制过来,粘贴到自己网站的images文件夹下,就可以浏览了,是不是也显示出对应的星座图片来了?如果图片没有正确显示出来,请检查birthday.asp文件中的图片文件路径。