Easy question for a good programmer...

J

jmp6789

I want to code a website which lists pictures and details of a long
list of cars in whichever order the client chooses (age, mileage,
colour etc).

In the filesystem of my website (ie server-side) I would like to be
able to place all of the details of each car in its own folder (the
pictures and some kind of file containing the details of the car -
let's call this the 'details file').

Surely the natural way to program this is:
1) Create a class 'Car'.
2) Count the number of cars in the filesystem.
3) Make each car in every folder an instance of the Car class.
4) Create an array of Cars and add each car instance to the array.
5) Sort the array however you like with a bit of javascript.

The problem I have is that I don't know how best to handle the
situation when you need to access information in a folder other than
the one that the main HTML file is in. Of course, I could just put all
of the details of every car in the same HTML file, with all of the
pictures in the same folder, but this is a very unwieldy and ugly
solution. It would be far more elegant, when I want to add a new car
to the database, to simple create a new folder in the 'All_Cars'
directory and fill it up with the pictures and the details file. The
car-folder-counting algorithm should add this new car to the array
automatically.

What type of file should the details file be? One possible solution is
to make it a text file, and then to read this file. Is this possible
with javascript? Alternatively, could it be a javascript file
containing code which creates an instance of the car class? This is
all very well, but how do you return the new car to the calling code?
It is easy to call javascript code from another file in HTML
(something like <script src="All_Cars/Mercedes/merc1/details.js"></
script>), but this is different to calling javascript code from
'within javascript'.

Any help much appreciated!
 
T

Thomas 'PointedEars' Lahn

I want to code a website which lists pictures and details of a long
list of cars in whichever order the client chooses (age, mileage,
colour etc).

In the filesystem of my website (ie server-side) I would like to be
able to place all of the details of each car in its own folder (the
pictures and some kind of file containing the details of the car -
let's call this the 'details file').

Surely the natural way to program this is:

It isn't. As your Subject is not the natural way to post on Usenet:
the Subject should be *descriptive* of the article; it is not there
to compete for attention.

http://jibbering.com/faq/ pp.
1) Create a class 'Car'.

Do you mean client-side scripting? If yes, there is no implementation yet
that supports classes, those are all languages using prototype-based
inheritance.

If you mean server-side scripting, it could only be ASP.NET.
2) Count the number of cars in the filesystem.
3) Make each car in every folder an instance of the Car class.

This is a case for using a database management system instead.
4) Create an array of Cars and add each car instance to the array.

And how are clients without script-support supposed to view cars, let alone
order them?
5) Sort the array however you like with a bit of javascript.

That is the only thing that should be done only client-side, however only as
a means to reduce roundtrips, with a viable server-side alternative.
The problem I have is that I don't know how best to handle the
situation when you need to access information in a folder other than
the one that the main HTML file is in. [...]

Your problems are caused by your wrong approach. However, standard relative
URI references[1] can be used to access such resources:

/ DocumentRoot directory
.../ Parent directory
.../foo Sibling directory


HTH

PointedEars
___________
[1] http://rfc-editor.org/rfc/rfc3986.txt
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
oglegroups.com>, Sun, 12 Aug 2007 05:44:43, (e-mail address removed) posted:
I want to code a website which lists pictures and details of a long
list of cars in whichever order the client chooses (age, mileage,
colour etc).

In the filesystem of my website (ie server-side) I would like to be
able to place all of the details of each car in its own folder (the
pictures and some kind of file containing the details of the car -
let's call this the 'details file').

You seem to consider 'folder' and 'file' interchangeable.

For each type of car, use a single file which, considered as javascript,
holds an object describing a car. Maintain these files.

Compose and use a simple pre-processor which writes a file "fleet.js" as
follows :

literal var mymotors = [
copy contents of each car file in turn, followed by a comma
literal {} ]

Include "fleet.js" in your page as usual, and you have access to car
data; you may want to remove or not include the final item, which was
only included as a possible simplifier of the copying. Debug. Adapt.

When you edit your data, re-run the pre-processor.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top