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!
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!