pls help

Results 1 to 3 of 3

Thread: pls help

  1. #1
    Join Date
    Dec 1969

    Default pls help

    &nbsp;<BR>Hi,<BR>The below script giving no error but not counting and recording hits to database. <BR>I m planning to display hits at any other page like;<BR>monday : 1hit<BR>tuesday : 5 hits<BR>wednesday : 2 hits<BR>/ <BR>/<BR>/<BR>/<BR>I really need your help.<BR>Thank you very much<BR><BR>---------------------------------------------------------------------<BR>MDB file<BR>table name : gunler<BR>table fields : id, dayname, hit<BR><BR>count.asp ---- which i include to pages to be counted.<BR>&#060;% <BR> Dim weekdayz <BR> weekdayz = Array ("monday" , "tuesday" , "wednesday" , "thursday" , "friday" , "saturday" , "sunday" ) <BR> today=LCase(WeekdayName(Weekday(Date))) <BR><BR> For i=0 To 6 <BR> If today=weekdayz(i) Then <BR> dayname=i <BR> exit For <BR> End If <BR> Next <BR><BR> Set hit_bag=Server.CreateObject("ADODB.Connection" ) <BR> hit_bag.Open("Provider=Microsoft.JET.OLEDB.4.0; Data Source=&#039;" & Server.MapPath("hit.mdb" ) & "&#039;" ) <BR> hit_SQL="Select * From gunler where id= &#039;" & dayname & "&#039;"<BR> <BR> Set RSHit_bag=Server.CreateObject("ADODB.RecordSet" ) <BR> RSHit_bag.Open hit_SQL, hit_bag, 1, 3 <BR> Do While Not RSHit_bag.Eof <BR> <BR> RSHit_bag("hit")=RSHit_bag("hit" )+1 <BR> RSHit_bag.Update <BR> <BR><BR> RSHit_bag.Movenext <BR> Loop <BR>%&#062; <BR>

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default sigh...

    ok first you MAY have to lose the &#039;<BR><BR>try this<BR><BR>hit_SQL="Select * From gunler where id= " & dayname <BR><BR>how many records do you think this should return??<BR><BR>i would have to say (if you have things right only ONE) then why do you need the loop???<BR><BR>should you just not increase it by 1 and not bother with the loop??<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Akhilesh right...and more!

    This is about as silly a code as you could use:<BR><BR>******** quote ***********<BR>Dim weekdayz <BR>weekdayz = Array ("monday" , "tuesday" , "wednesday" , "thursday" , "friday" , "saturday" , "sunday" ) <BR>today=LCase(WeekdayName(Weekday(Date))) <BR><BR>For i=0 To 6 <BR>If today=weekdayz(i) Then <BR>dayname=i <BR>exit For <BR>End If <BR>Next <BR>********* end quote *********<BR><BR>You could get *exactly* the same result by doing:<BR>&#060;%<BR>dayname = Weekday(Date)-1<BR>%&#062;<BR>Except that dayname is a bad name for;s really day number, isn&#039;t it?<BR><BR>And then you should just use SQL to update the hit count, instead of doing it with RS.Update and Movenext and all that crap.<BR><BR> could accomplish the same thing as *ALL* that code by simply doing:<BR><BR>&#060;%<BR>... make the connection to the DB in the variable you named "hit_bag" ...<BR><BR>SQL = "UPDATE gunler SET hit = hit + 1 WHERE id = ( Weekday(Date()) - 1 )"<BR>hit_bag.Execute( SQL )<BR>%&#062;<BR><BR>Look! No VBScript to get the day of the week, at all!<BR><BR>Now, that code only works, as is, in Access. It would take a tiny bit of tweaking to use in SQL Server and probably wouldn&#039;t work quite right, at all, with other DBs. If you want a universal solution, using ANSI SQL, you could do:<BR><BR>&#060;%<BR>... make the connection to the DB in the variable you named "hit_bag" ...<BR><BR>SQL = "UPDATE gunler SET hit = hit + 1 WHERE id = " & ( Weekday(Date()) - 1 )<BR>hit_bag.Execute( SQL )<BR>%&#062;<BR><BR>Do you see the difference? In that code, we get the Weekday from VBS code instead of letting the DB do it automatically.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts