This topic is locked

How to rank database records

6/26/2007 12:32:00 PM
PHPRunner Tips and Tricks
Sergey Kornilov admin

Here is how this can be done:

  1. Modify SQL query adding a calculated field named 'Rank'

select [ID],

0 as Rank,

[Make],

...

From [Cars]


2. Proceed to 'Fields order and totals' screen, make sure this 'Rank' field appears in the very first column of your grid and set "View as" type to Custom.

Put the following code there:

$_SESSION["Rank"] += 1;

$value = $_SESSION["Rank"];


3. Add the following code to List page: BeforeProcess event:

$_SESSION["Rank"]=0;
S
smith 11/26/2010

I'm getting error now
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; FunWebProducts; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET CLR 1.1.4322; .NET4.0C)

Timestamp: Sat, 27 Nov 2010 04:38:41 UTC
Message: '$_SESSION' is undefined

Line: 2

Char: 152

Code: 0

URI: http://XXXXXXXXXX/XXXXXXXXXXX/include/runnerJS/events/pageevents_Items_to_be_purchased.js
contents of the above .js file
var pType = Runner.pages.constants.PAGE_REPORT;
Runner.pages.PageSettings.addPageEvent("Items to be purchased", pType, "afterInit", function(pageObj, pageid){

$_SESSION["Rank"]=0;
// Place event code here.

// Use "Add Action" button to add code snippets.;

});
everytime I refresh the page, value of the Rank field keepon adding. if page contains 10 items first time load shows 1 to 10 next refresh 11 to 20 and so on

Sergey Kornilov admin 11/28/2010

You trying to add PHP code to Javascript event. Make sure you follow steps provided by this tutorial.

S
smith 11/28/2010

adding $_SESSION["Rank"]=0; to the Report page: Before SQL query solved the problem.

thanks



You trying to add PHP code to Javascript event. Make sure you follow steps provided by this tutorial.

N
netrebelos 12/1/2010

Add a column (int or real - whatever you want) in your database and name it rank or weight. Edit SQL query from phprunner like this:
column 1,

column 2,

column 3,

[color="#000080"]FROM <your_table>

DESC.
Now the results with the higher value at rank column will be first at search results!!!