473,325 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How To Sort and Report from an Array ?

I need to extract records from a database subject to conditions and
only thereafter give the users the choice of which fields to sort the
results on.

In this situation I can't write back to a temporary file and then
select all from that file on the different sort orderings.

I figured that the only way out would be to write to an array from the
first recordset set creation. Then write the report to the screen
from the array and users can choose different sort orders and it would
extract again and report from that same array.

( 1 )
Only problem is that I havn't the faintest idea of how to create and
write to the array. Or how to query it. Is it similar to the first
database report.?

Would anyone perhaps know of a simple tutorial resource that
demonstrates this method.?

( 2 )
Or do I need to think right outside the box and take the first report
in a more efficient way. Problem is that I need to take only one
record whenever the value changes in a particular field. Could my SQL
statement use ordering on one field to take the recordset but order on
another field for the output. I wouldn't have tought so.

thanks

.les.

Feb 15 '06 #1
6 1913

Les Juby wrote:
I need to extract records from a database subject to conditions and
only thereafter give the users the choice of which fields to sort the
results on.

In this situation I can't write back to a temporary file and then
select all from that file on the different sort orderings.

I figured that the only way out would be to write to an array from the
first recordset set creation. Then write the report to the screen
from the array and users can choose different sort orders and it would
extract again and report from that same array.

( 1 )
Only problem is that I havn't the faintest idea of how to create and
write to the array. Or how to query it. Is it similar to the first
database report.?

Would anyone perhaps know of a simple tutorial resource that
demonstrates this method.?

( 2 )
Or do I need to think right outside the box and take the first report
in a more efficient way. Problem is that I need to take only one
record whenever the value changes in a particular field. Could my SQL
statement use ordering on one field to take the recordset but order on
another field for the output. I wouldn't have tought so.

thanks

.les.

A quick google threw up this result:
http://www.4guysfromrolla.com/webtech/072199-1.shtml

which may give you some ideas about how to accomplish the task.
Basically you can make the column heads hyperlinks passing the 'Order
By' variable in the querystring, then dynamically create your SQL query
using the variable passed in the querystring.

/P.

Feb 15 '06 #2
Les Juby wrote:
I need to extract records from a database subject to conditions and
only thereafter give the users the choice of which fields to sort the
results on.

In this situation I can't write back to a temporary file and then
select all from that file on the different sort orderings.


We do this commonly. A generic example, with ADODB.Recordset RS:

for (var Rows=[]; !RS.EOF; RS.MoveNext()) {
for (var Cells=[],i=0; i<RS.Fields.Count; i++)
Cells.push(RS.Fields(i).Value)
Rows.push(Cells)
}
function ResultSort(x,y) {
var C = Request.Form("SortBy").Item || 0,
O = Request.Form("Order").Item == "Desc" ? -1 : 1
return x[C]>y[C] ? O : x[C]
}
Rows.sort(ResultSort)

In the above example, the default behavior is to sort in ascending order on
column 0, but deferring to a passed sort column "SortBy" and ordering
"Order".


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Feb 15 '06 #3
Dave Anderson wrote:
function ResultSort(x,y) {
var C = Request.Form("SortBy").Item || 0,
O = Request.Form("Order").Item == "Desc" ? -1 : 1
return x[C]>y[C] ? O : x[C]
}
Rows.sort(ResultSort)


I hate when OE tries to think for me. The return line should read:

return x[C]>y[C] ? O : x[C]<y[C] ? -O : 0
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Feb 15 '06 #4
Les Juby wrote:
I need to extract records from a database subject to conditions and
only thereafter give the users the choice of which fields to sort the
results on.

In this situation I can't write back to a temporary file and then
select all from that file on the different sort orderings.

I figured that the only way out would be to write to an array from the
first recordset set creation. Then write the report to the screen
from the array and users can choose different sort orders and it would
extract again and report from that same array.

( 1 )
Only problem is that I havn't the faintest idea of how to create and
write to the array. Or how to query it. Is it similar to the first
database report.?

Would anyone perhaps know of a simple tutorial resource that
demonstrates this method.?

( 2 )
Or do I need to think right outside the box and take the first report
in a more efficient way. Problem is that I need to take only one
record whenever the value changes in a particular field. Could my SQL
statement use ordering on one field to take the recordset but order on
another field for the output. I wouldn't have tought so.

thanks

.les.

On 15 Feb 2006 13:16:28 -0800, "Paxton" <pa*******@hotmail.com> wrote:


A quick google threw up this result:
http://www.4guysfromrolla.com/webtech/072199-1.shtml

which may give you some ideas about how to accomplish the task.
Basically you can make the column heads hyperlinks passing the 'Order
By' variable in the querystring, then dynamically create your SQL query
using the variable passed in the querystring.

/P.


Thanks for that. It is pretty much what I would normally do, but I
think maybe I havn't explained the problem properly here.

My initial recordset is maybe only 10% of the database, and a whole
lot of complex ordering and filtering has happened to get the
recordset for display.

The user now needs to be able to view that recordset in different
orderings, and usually (as you've suggested) I'd be able to just
generate the search again with querystrings passed from hyperlinks in
the column titles. But I can't do that as I'd have to filter from the
database first on special orderings to get the primary recordset.
Catch 22.

The other method is to do the first filter and feed the results into a
temporary table. Then use that table for taking the different sorts
from. Problem here is that a second user could put results in there
while the first user is still looking at his different sorts. And
that's quite likely with this many users. To put a random ID on
records with a session variable to keep to your results only is the
worst case solution. This table could then get huge, would need
maintenance, and could corrupt. How do you clear it out without
wiping out someone else's results-in-progress.?

That's why I thought an array would be the solution. It's private (in
memory) for each user, fast, and disappears when they do.? Wouldn't
that work.? But can you use it like a normal table.?

.les.
Feb 16 '06 #5
On Wed, 15 Feb 2006 16:18:43 -0600, "Dave Anderson"
<GT**********@spammotel.com> wrote:
Les Juby wrote:
I need to extract records from a database subject to conditions and
only thereafter give the users the choice of which fields to sort the
results on.

In this situation I can't write back to a temporary file and then
select all from that file on the different sort orderings.


We do this commonly. A generic example, with ADODB.Recordset RS:

for (var Rows=[]; !RS.EOF; RS.MoveNext()) {
for (var Cells=[],i=0; i<RS.Fields.Count; i++)
Cells.push(RS.Fields(i).Value)
Rows.push(Cells)
}
function ResultSort(x,y) {
var C = Request.Form("SortBy").Item || 0,
O = Request.Form("Order").Item == "Desc" ? -1 : 1
return x[C]>y[C] ? O : x[C]
}
Rows.sort(ResultSort)

In the above example, the default behavior is to sort in ascending order on
column 0, but deferring to a passed sort column "SortBy" and ordering
"Order".


Sorry Dave, I'm just a simple Classic ASP child ...... I think you're
presuming here that I have created an array and am now happily
reporting from it. If so, not so.!

Is that the presumption .... and if so how would I get the first
results into the array to get out the second level reports...?

This is why I was hoping there might be a simple (but detailed)
explanation somewhere....

thanks for the help

.les.

Feb 16 '06 #6

"Les Juby" <le*****@anti-spam.iafrica.com> wrote in message
news:43***************@news.telkomsa.net...
I need to extract records from a database subject to conditions and
only thereafter give the users the choice of which fields to sort the
results on.

In this situation I can't write back to a temporary file and then
select all from that file on the different sort orderings.

I figured that the only way out would be to write to an array from the
first recordset set creation. Then write the report to the screen
from the array and users can choose different sort orders and it would
extract again and report from that same array.

( 1 )
Only problem is that I havn't the faintest idea of how to create and
write to the array. Or how to query it. Is it similar to the first
database report.?

Would anyone perhaps know of a simple tutorial resource that
demonstrates this method.?

( 2 )
Or do I need to think right outside the box and take the first report
in a more efficient way. Problem is that I need to take only one
record whenever the value changes in a particular field. Could my SQL
statement use ordering on one field to take the recordset but order on
another field for the output. I wouldn't have tought so.

thanks

.les.


Use the Sort property of the Recordset object:
http://msdn.microsoft.com/library/en...ropertyado.asp
You can continue to sort/filter the data as you are currently doing, then
once you've retrieved the filtered data into a Recordset object, set the
Sort property for that object based on the sort column indicated by the
user.
Feb 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
4
by: Brett | last post by:
I have two arrays and i wish to sort the first one numerically, but after sorting, I would like the second array to be in the same matching order as the first array. ie. @l1={3,1,2};...
12
by: Thomas Mlynarczyk | last post by:
While experimenting with Array.sort(function) I got different results from different browsers. How can that be? Shouldn't I expect identical results - given both the input array and the sort...
11
by: James P. | last post by:
Hello, I have a report with the Priority field is used as sort order and grouping. The problem is the data in this Priority field if sorted in ascending order is: High, Low, and Medium. How...
5
by: Terri | last post by:
The following query will give me the top ten states with the most callers. SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State FROM Callers GROUP BY Callers.State ORDER BY...
4
by: Nhmiller | last post by:
This is directly from Access' Help: "About designing a query When you open a query in Design view, or open a form, report, or datasheet and show the Advanced Filter/Sort window (Advanced...
1
by: fecket | last post by:
The following code is used in my db to change the sort order of the report to various fields. I want to take this one stage further and use maybe a Case Select to give 2 or 3 different options to...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
2
evilmonkey
by: evilmonkey | last post by:
I am trying to sort an array by name ( that works) but I only need each sorted name to show up once, regardless of how many times it shows up in the sort. Where do I go from here? public class...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.