20/20 Applications Forums
SearchForum Home
  General Comments and Questions  20/20 DataShed  Adding Present ...
 Adding Present number of Items in Start page...
 
imgOfflineJaBren
33 posts
www.LeaseTakeOvers.ca
4th
Joined
8/14/2006

Adding Present number of Items in Start page...
Posted: 22 Sep 06 8:29 AM Modified By 20/20 Applications Tech  on 9/23/2006 9:20:35 AM)

Hi All;

We now have over 120 vehicles in our database and over 200 members :)

We would like to add this kind of information of the start page:



We presently have X Vehicles in our database

Of course the X is the number of ACTIVE Items in our database.

Is there an ease way of doing this?

Cheers :)


_______________ www.LeaseTakeOvers.ca
imgOffline20/20 Applications Tech
199 posts
www.2020applications.com/
1st
Joined
5/24/2006

Re: Adding Present number of Items in Start page...
Posted: 23 Sep 06 10:36 AM

Hello JaBren,

Yes this is possible, and an excellent request.

First...you should step through carefully step through this tutorial. It will demonstrate all of the necessary steps and step you through the entire process of building your own "plug-in". Once you've done that...then the following information will make sense.

Next...after you have completed all the steps in that tutorial, simply do this:

  1. Open the "myCopyright.asp" script that you created in the tutorial.

  2. Delete all of its contents.

  3. Copy-n-paste the following code into that file (-- replace everything that was in that file).

    <%@ Language="VBScript" ENABLESESSIONSTATE="False" %>
    <%
    Option Explicit
    response.buffer = true

    dim booleanIsParentFolder
        booleanIsParentFolder = True
    %>
    <!--#include file="_globals.asp"-->
    <%
    dim strHTMLOutput
        strHTMLOutput = "<div>There are "& WriteDisplayItemCount &" items in our database.</div>"

    response.write(strHTMLOutput)




    FUNCTION WriteDisplayItemCount

    dim strItemCount

         IF len(Application(strApplicationInstance &"DisplayItemCount")) > 0 THEN
         strItemCount = Application(strApplicationInstance &"DisplayItemCount")
         ELSE

         GetDBConnection 0,1,0

         on error resume next

         dim strSQL
             strSQL = "SELECT Count(itemID) AS itemCount FROM items WHERE items.approved_for_display AND items.show_on_website "

              IF optionBoolean("itemsExpire") AND optionBoolean("hideExpiredFromPublic") THEN
              strSQL = strSQL &" AND (NOT isDate(items.closing_date) OR (CDbl(items.closing_date) > CDbl(DateAdd('N',"& optionLng("thisAppMinutesOffset") &",Now())))) "
              END IF

             strSQL = strSQL &";"

         dim objRs
         set objRs = cn.Execute(strSQL)

              IF err.Number <> 0 THEN
              strItemCount = "0"
              END IF
              err.Clear

              IF objRs.eof THEN
              strItemCount = "0"
              ELSE

              strItemCount = CStr(objRs("itemCount"))

              Application.Lock
              Application(strApplicationInstance &"DisplayItemCount") = strItemCount
              Application.Unlock

              END IF

         Destroy(objRs)

         on error GoTo 0

         Destroy(cn)

         END IF

    WriteDisplayItemCount = strItemCount

    END FUNCTION
    %>

    Really..."copy-n-paste" the above code. If you don't, then the line breaks above might confuse the issue -- but if you copy-n-paste the correct line-breakage will be preserved.

  4. Then you might want to rename your plug-in file and alter the references to that plug-in because perhaps "myCopyright.asp" (as described in the tutorial) isn't a suitable file name for this tool. I have call my own copy "_2020DisplayItemCount.asp".

I have uploaded my version of this file here: 2020datashed_2020DisplayItemCount(free).zip. Feel free to study it.

Note a couple of cool features of this code:

  • This plug-in includes 20/20 DataShed's "_global.asp" file -- which is a repository of useful functions and subroutines. This is helpful in this case for the database connection and allows us to connect to the database in one simply line of code:

    GetDBConnection 0,1,0
  • You should customize the line starting with "strHTMLOutput = ". This is the line of code where you can add or edit your own HTML and make this thing look however you please.

    Alternatively, you could change it to this:

    strHTMLOutput = WriteDisplayItemCount

    then this plug-in would simply output a number...and then you can do all your own markup directly in the template. It's up to you.

  • All the business happens within the WriteDisplayItemCount function.

  • And this plug-in makes use of the Application() cache. So that once the application has counted the items once, it remembers that number for a while instead of having to process the database connection and query over-n-over-n-over again with every page load.

All in all...it's a pretty smart snippet of code if I do say so myself!


Regards,
20/20 Applications Tech
  General Comments and Questions  20/20 DataShed  Adding Present ...
Forum Home  Search         

 Other Forums (For Registered Users Only)

Please note that registered users of our forums can also post in the private forums.

Our private forums are:

  • Will Work for $$$: A great place for webmasters who have experience with 20/20 products to post their portfolio and gain exposure.
  • Will Pay $$$: A great place for users of 20/20 products to find experts who can assist with configuration, installation, design, maintenance, and customizations.

These additional forums are an excellent way to connect with others and find or share your experience.

      

Register  Login
Copyright © 2002 - 2006 by 20/20 Applications