Resorting webpage items (ASP? Javascript? How to start?)

They have: 318 posts

Joined: Mar 1999

Hello,

There are various sites (eg: download.com) where users can organize search results through clicking:

Re-sort by: Title | Buy | Pick | Date Added | Downloads | File Size

I want this feature to be present at my site. It's because I have a large bookstore where I want users to have the opportunity to organize books through the book's title or author. I don't know how to do this. I know the required language is ASP, but I would prefer using javascript (I am more familiar with javascript than ASP). I would prefer finding a premade code that can be used at my site. If it can only be done in ASP, I'd still like to have a premade code in ASP cause I don't know how ASP works.

Thanks in advance,
Sabrina

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Sabrina,

First off, how is your data maintained on the web? flat-file database, sql database, comma-delimited file, typed into the HTML page?

There is a javascript arrayName.sort() method, but you need to have your data in arrays.

Also what kind of server do you have? NT or UNIX? ASP is a microsoft thing, so you would need NT.

Finally, asp is not the only choice. You can use PHP with a relational database (mySQL is the current rage), or a perl script.

Whatever you decide on, though, will probably require a lot of work. Hope you like to get your fingers dirty Smiling

Vinny

Where the world once stood
the blades of grass cut me still

They have: 318 posts

Joined: Mar 1999

Whoah! Okay, first of all, the content is typed in a html page. I'll stick to the javascript arrayName.sort() method. I wouldn't mind putting all my data in arrays. As for the server, my site will be hosted on a server that supports ASP data. Admittingly, I don't want to go into ASP because I don't have the time to learn another computer language. I'll stick with the javascript, and I'll risk getting my fingers dirty if I have to.

Tell me what I have to do, or if it's at your site, I'd like to know which section to go through. I saw 4 menus and don't know where to go to in accomplish this sort of task.

Thanks!
Sabrina

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Sabrina,

Sad Sorry to say there is no script on my site that does exactly what you're asking. However, I won't mind if you look through the scripts, anyway. Smiling
Because I don't know your javascript comfort level: You might find the following scripts interesting and/or helpful -- the arguments object and dynamically creating selection lists (The Learning Center) and Rolodex (I, Object).
Since I don't have enough info and because you're willing to get down and dirty, much of this will be general. It will also be disjointed because I'm writing this and doing other things at the same time -- sorry Smiling
You will have to create arrays for each of the items you want to search on -- author, title, etc. The arrays could look like:
var myTitles = new Array();
myTitles[0] = "100 Years of Solitude|0";
myTitles[1] = "the Sound and Fury|1";

var myAuthors = new Array();
myAuthors[0] = "Marquez, Garbriel Garcia|0";
myAuthors[1] = "Faulkner, William|1";

Note the vertical bar and number at the end of the string: you can use that number to access the other arrays by using the split() method -- arrayName[i].split("|")

You loop through the array based on the user selection, get the embedded index number and use it to access the other arrays:

arrayName.sort();
for (i=0;i

Where the world once stood
the blades of grass cut me still

They have: 99 posts

Joined: May 1999

How to define your arrays first:

books_array=new Array(1000); // 1000 = the # of elements

detail_array=new Array(10); // use to store book info

--To store the content in your html, you could assign the content to the books_array using a deliminated method.

books_array[1]="Author_last, Author First, Subject, Title, Description";
books_array[2]]="Author_last2, Author First2, Subject2, Title2, Description2";

--When you wish to sort by a different index (Author_last, Title, etc) you will need to do two things, access that field and also track how the fields correlate.

--One method would be to use the split function on each array element to re-order the field sequence.

new_array=new Array(1000);

//split the main books_array element into fields using
//the .split function
sequence_shift=books_array[1].split(",");

//reassemble a new order with the field you wish to sort by in the primary position
new_element = sequence_shift[2]+sequence_shift[0]+sequence_shift[1]+sequence_shift[3]+sequence_shift[4];

//assign to new sorted_array
new_array[1]=new_element;

--you would obviously do this in a for/next loop sequence to catch all the elements and automate the field sequencing.

--Once you have assembled your new array (sorted_array), use the .sort function

sorted_array=new Array(1000);
sorted_array=new_array.sort();

You now have a new array sequenced by Subject..

Run a for/next loop to output the displayed info.

Disclaimers:
1) This is a poor way to do what you wish, I much prefer sql-database.
2) If the Array's are too large, it could cause processing probs.
3} I am sure that there are a bunch of slicker ways to do this, I just banged out a quicky for you.

Regards,

Tazman

They have: 318 posts

Joined: Mar 1999

Okay, I've read both messages. I understand that these variables go within coding, but I don't know where to apply them in my html file... what goes in the tag, or tag within the book title, author, etc. I guess you can say I'm more of a beginner at javascript (heck, at least it's better than knowing nothing about PHP, SQL, ASP, etc.). I often go to those free javascript coding places and edit the coding learning it along the way).

What would really help me out (and save lots of time) is that I read through the coding of a premade html file which contains that javascript coding (as both of you mentioned) so I get a better idea and better chance of editing out the coding to my advantage. If you know a site that has the same concept - resorting items with javascript coding used, I'd love to see it!

BTW, I am also hoping to allow users not only sort books by the title and author, but also by the publisher's date (when the book was published).

Sabrina

In the mean time, I will hunt the web for a site with the javscript coding.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Sabrina,

(I'm sure tazman would agree -- at least in general principle -- with what I'm going to say)

Don't want to bust your bubble, but...this little task you are in the process of undertaking is no little bit of cut & paste code. You are trying to write an application, not a little snippet of javascript. What both he and I outlined for you (note the word outlined? It means it's not thought-out, won't work first time out, probably not even tenth time out) is only part of what you would need to do. You would still need to provide a form and then code to access the data. And, if you wanted it to look 'pretty', you would need more code. And, if you wanted it be fast, you would have to work on it some more.
Did you look at the Rolodex scripts at my site? The arguments object script? Did you understand them? If not, you are in deep.

Quote:
I guess you can say I'm more of a beginner at javascript

To all beginners I meet, I suggest the following:
1) http://www.htmlgoodies.com -- the javascript primer
2) SAM's Javascript in 24 hours
3) The BareBones Guide to HTML -- an HTML document somewhere on the web
4) rightClicking on sites that interest you, downloading them, and modifying their code to see what makes it tick.

To all novices and experts who are not afraid of books, I recommend:
1) Danny Goodman's Javascript Bible, and
2) any book by O'Reilly publishers.

Hi tazman: Smiling
Love the different approach. Interesting to see how other minds work.

Vinny

[Edited by Vincent Puglia on 07-30-2000 at 01:21 AM]

Where the world once stood
the blades of grass cut me still

They have: 318 posts

Joined: Mar 1999

Okay, I'm sorry for being so 'beginnerish'. School's starting soon and I'm worried more time will be spent on learning a language (an application for that matter) than finishing off my site. I thought I could take the easy way out on this. I took a glance at your site, and I'll return to it.

What would be the best recommended language to use to ease the load? I'll start reading up on it and come back to this forum whenever I may need the occasional help from someone.

Thanks,
Sabrina

24 days until I start with the textbooks! Oh joy! Sad

[Edited by SabrinaP on 07-30-2000 at 01:38 AM]

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Sabrina,

I can't tell you what to learn since it would depend on what you already know and have. For example, if you are comfortable with javascript, php might be the way to go. If you know basic, try asp. In either case, you will need a database to store the data. The usual inexpensive choices are mySQL or Access -- the former is usually run on Unix servers; the latter you run under windows.
Given the amount of time you have before school starts, you might want to leave your site as is and simply learn more javascript -- you will eventually need to learn that well, anyway.

Vinny

Where the world once stood
the blades of grass cut me still

They have: 99 posts

Joined: May 1999

Sabrina:

Sorry I have not contributed to the thread, but I was out of town (although Vinny has it well under control!).

I would recommend that you take a a look at the mySQL as a database to use on the server. They do have both a UNix/Linux and DOS based version. I have used it extensively and have nothing but positives to say about it. That only addresses one aspect of your application (and that is really what you are looking at not just some miscellaneous code). Learn more about javascript, also spend some time on perl. They will both do you well!! The learning curve differs by person and obviously time availability.

I would concur with Vinny that you should not tackle the site until you have done a bit more legwork.

Tazman.

Hi Vinny:

Yep, I was working on my post at the same time you were, so when I put it up, I was interested in seeing your approach. As you said, it is always intriguing to see the solution from a different angle!! Smiling
Tazman

[Edited by tazman on 07-31-2000 at 08:13 PM]

They have: 99 posts

Joined: May 1999

Okay Sabrina:

Given that you are under an education crunch, I threw together a quick application. It works, but needs to be dressed up.

1) Here is your frames page.

Contents

This document requires a browser that can view frames.

2) here is your left sidebar page

<script LANGUAGE="Javascript">
function sequence(order){
books=new Array(100);//Main data array containing book data--set to number of records necessary!!
i=0;//record counter
books[i]="Author|Title|Date|Subject";i++;//header record
books[i]="Smith,Joe|Over the hill|1999/10/1|Aging";i++;
books[i]="Doe,Jane|See Spot Run|1901/1/15|Early Childhood Development";i++;
books[i]="Canter, Jeff|Running in Place|1965/2/5|Career Advancement";i++;
books[i]="Martin, Austin|Oilspots on the Driveway|1978/5/1|Auto Repair";i++;
total_books=i-1;
fields=new Array(4);
if(order=="A"){
fields[0]=0;
fields[1]=1;
fields[2]=2;
fields[3]=3;
}else if(order=="T"){
fields[0]=1;
fields[1]=0;
fields[2]=2;
fields[3]=3;
}else if(order=="D"){
fields[0]=2;
fields[1]=0;
fields[2]=1;
fields[3]=3;
//default to Subject
}else{
fields[0]=3;
fields[1]=0;
fields[2]=1;
fields[3]=2;
}
top.main.document.open;
top.main.document.write('');
top.main.document.write('Booklist');
sequenced_array=new Array(total_books);
sorted_array=new Array(total_books);
header=new String();
for(j=0;j<=total_books;j++){
temp_array=new Array(4);
sequenced_record=new Array(4);
sorted_array=new Array(total_books);
temp_string=new String(books[j]);
temp_array=temp_string.split("|");
for(k=0;k<4;k++){
sequenced_record[k]=temp_array[fields[k]];
}
if(j==0){
header=sequenced_record.join("|");
}else{
sequenced_array[j]=sequenced_record.join("|");
}
}
sorted_array=sequenced_array.sort();
top.main.document.write(header+"");
for(j=0;j");
}
top.main.document.write('');
top.main.document.close();
}//end of function sequence
</script>

List Books by

Author

Title

Date

Subject

Save them both off in a single directory. Load the main frames page. Click on the sequence by links in the left frame and the results display in the main frame.

You can take the code and play around with it.

Tazman Wink

[Edited by tazman on 07-31-2000 at 08:16 PM]

They have: 318 posts

Joined: Mar 1999

Thanks taz! I'll try out the coding and put my researching on sql and asp on hold.

Sabrina

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.