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 :)
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:
Open the "myCopyright.asp" script that you created in the tutorial.
Delete all of its contents.
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.
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.
strHTMLOutput =
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!