faqts : Computers : Programming : Languages : Asp : ASP/VBScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 32 people (81%) answered Yes
Recently 2 of 3 people (67%) answered Yes


How do you create a New/Update icon function?

Jun 27th, 2000 23:11
Rory Knowles,

Do you have a listing/news site, or basicaly have a database that you 
update regularly and want to let people know if the record is new or if 
it has been updated? Well here is an easy to use function that will do 
this for you. 
First you need to create two icons, one called 'new.gif' and the other 
called 'updated.gif', and they should look like 'new' and 'update'. 
Then, in the database design view you must create 2 text fields, 1 is 
called dte, which will be used for the input of the new date, the other 
is called upd, which is used to input the date in so we know when it is 
In your code which you use to add the data to the database, you need to 
add :
set RS = conn.Execute(Insert into table (dte, upd) values ('" & DATE & 
"', '" & DATE & "'))
This is the function..
' new OR update icons function
function newadd(dtenw, dteup)
Dim lastweek, nw
    lastweek = (date-7)
    If NOT ISNull(dtenw) and ISNull(dteup) then
        if (CDate(dtenw)) >= (CDate(lastweek)) THEN 
          nw = " <img src='includes/images/new.gif' border=0 alt='New 
     within 7 days' align=absmiddle>"
          nw =  ""
        end if
        IF NOT ISNull(dteup) then
           if (CDate(dteup)) >= (CDate(lastweek)) THEN 
              nw = " <img src='includes/images/updated.gif' border=0 
     alt='Updated within 7 days' align=absmiddle>"
               nw = ""
           end if
        end if
    end if 
    newadd = nw
end function
Then to call the following function in your pages just do the following:
response.write newadd(RS("dte"), RS("upd"))
Thats all you have to do! It will show a new icon if there only a dte 
value, and no upd value, or if there is an upd value it will show an 
update icon. You can also call the dates from these fields out of the 
database depending on whether the record is new or updated like this:
    Dim dte
     If IsNull(RS("dte")) Then
        dte = ""
        if IsNull(RS("upd")) then
             dte = "Date: " & RS("dte")
            dte = "Date: " & RS("upd")
        end if
     End If
    response.write dte

© 1999-2004 Synop Pty Ltd