Counting How many times a result has been displayed

KMandalia
Posts: 301
Joined: Fri Jul 09, 2004 3:50 pm

Counting How many times a result has been displayed

Post by KMandalia »

in showresults i am doing (all caps are just for easy readability)

<loop skip=$ignore max=$SSc_hitsperpage $Url $UrlDisplay $Depth $Title $Description $Body $Size $Modified $Visited $id $Charset $rawrank $Docsize $urlseq $urlprofile>
<$next=($firsthitno+$loop)>
<result><!-- display the result record -->
<SQL NOVARS "UPDATE HTML SET VIEWS=(VIEWS+1) WHERE ID=$ID"></SQL>
</loop>

Obviously, the loop and next variables for the outer loop and inner sql statement are getting messed up somewhere so that when I display the 10 results, $next resets back to 1.

Kai did suggest use of local variables and so I tried using them but looks like I don't know the exact place I should be saving the loop and next variables.

Can you help me out here? I want to increment the Views field in html table for each result record I display.
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Counting How many times a result has been displayed

Post by Kai »

You can preserve $loop and $next from the outer list by enclosing your statement like this:

<local saveloop=$loop savenext=$next>
<SQL NOVARS "UPDATE HTML SET VIEWS=(VIEWS+1) WHERE ID=$ID"></SQL>
<$loop = $saveloop>
<$next = $savenext>
</local>
KMandalia
Posts: 301
Joined: Fri Jul 09, 2004 3:50 pm

Counting How many times a result has been displayed

Post by KMandalia »

That is exactly what I did and it didn't work (that is, it says there are 2000 results but only displays first 10) which forced me to post this thread.

If you print out the values without even saving to local variables they look OK. I think the problem is in search function right after calling showresults where it sets xloop=loop.

Isn't there any mode of sql function that just performs the update. I did see a couple threads about behavior of update within loop. My update only returns one row. But looks like it messes up.
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Counting How many times a result has been displayed

Post by mark »

max=$SSc_hitsperpage
will limit the loop to 10 (or whatever $SSc_hitsperpage is set to).
KMandalia
Posts: 301
Joined: Fri Jul 09, 2004 3:50 pm

Counting How many times a result has been displayed

Post by KMandalia »

I didn't understand how the reply is related to the question. Are you saying I should say <sql max=$SSc_hitsperpage novars......">

I think I need to update the views totally separately because may be loop and update don't work together?
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Counting How many times a result has been displayed

Post by mark »

You said you're only getting 10 of 2000 in the loop. max will limit how many are processed by the loop. If that's not the issue maybe you need post an exact code snippet of what you're doing.
KMandalia
Posts: 301
Joined: Fri Jul 09, 2004 3:50 pm

Counting How many times a result has been displayed

Post by KMandalia »

OK. Lets elaborate as much as I can.

What I want to do ultimately is to take into consideration clicks, views and CTR along with Pop and modified fields of html table when calculating result rank.

It was easy to add code in redir function to increment clicks. I just did

<sql novars "update html set Clicks=(Clicks+1) where Url=$u"></sql>

after this line,

<sql novars "insert into querylog values(counter,$REMOTE_HOST,$qinfo,$u)"></sql>

Also, I will be adding some extra sql statements in redir function that will update the CTR

so after

<sql novars "update html set Clicks=(Clicks+1) where Url=$u"></sql>

I will do,

<sql max=1 "select views from html where Url=$u"></sql>
<if $Views gt 0>
<sql novars "update html set CTR=(Clicks/Views) where Url=$u"></sql>
</if>


Now, I am left with two issues,

1) Update view field for each result record displayed.
2) Add some logic so as not to update views when user returns to the same set of results via next,previos links or page numbers.

For 1) the most logical choice is to updates views for pages as they are being fetched 10 at a time and displayed. So, I thought (and I may be wrong) i should update the views in showresults function in search script right after a result record is displayed so I did,

<local saveloop=$loop savenext=$next>
<SQL NOVARS "UPDATE HTML SET VIEWS=(VIEWS+1) WHERE ID=$ID"></SQL>
<$loop = $saveloop>
<$next = $savenext>
</local>

after,

<result>

and before,

</loop>

the problem is only the first page of results is being displayed even though there could be 2000 results returned.

I need your help in figuring out where and how to update the views so as i am updating views as I am fetching/displaying SSc_hitsperpage results at a time.

Later on, if we can get 1) working then I can figure out how to avoid duplication in updating view count.

I think this should clear out any confusion. There is nothing more to add on my part.
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Counting How many times a result has been displayed

Post by mark »

This is the unclear part "the problem is only the first page of results is being displayed even though there could be 2000 results returned." Are you saying that the first 10 results show but when you click "next" you get nothing? or what?

BTW, one sql would be more efficient than 2 and an if:
<sql novars "update html set CTR=(Clicks/Views) where Url=$u and Views>0"></sql>
KMandalia
Posts: 301
Joined: Fri Jul 09, 2004 3:50 pm

Counting How many times a result has been displayed

Post by KMandalia »

Yes.

when I have the sql for updating views, I don't see the pages and next previous links.

Thanks for the tip about combining sql statements.
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Counting How many times a result has been displayed

Post by mark »

You probably need to preserve/restore $indexcount in addition to $loop and $next.
Post Reply