Jump to content

Train Schedule


MadFly

Recommended Posts

Hi EveryoneI am looking to make a page with the schedules of the local trains.I would like to have a few drop down menus where users can select the following...From:To:Day:Arrival Time:Then the user will be able to quickly and easily see at what time the train leaves and at what time it arrives at destination.Have been looking around, but I am not able to find what I'm looking for. Any help?

Link to comment
Share on other sites

I'm not entirely clear on the specifics of your application, but I can say this. The solution will involve some non-trivial scripting, either on the user's browser (JavaScript) or your server (e.g., ASP, PHP), or both, possibly involving AJAX as well.That is why looking around will not turn up very much. We are not discussing something moderately simple and generic, like a plug and play animation. This will require a lot of resources.How is your data stored? A database like mysql, flat files, XML, hard-coded into your HTML document?What server-side language would you be using?How do you want to interact with the data? Should all of it be a part of your HTML document? Stored as javaScript objects, maybe, or hidden HTML elements? Do you want to fetch the data in response to a form request, or maybe an AJAX request?How are your javaScript skills?

Link to comment
Share on other sites

The data can be hardcoded into the html or sql or javascript, which ever is easiest and quicker.Would be nice if i were able to export data to microsoft excell and then create menus to get data from certian cells or something.The data is currently on the "official" website... at MetrorailGot to run now, will pop in later to check in.

Link to comment
Share on other sites

If you have internal access to metrorail's database, that would be ideal.Otherwise, you'll need to scrape the data, which is not a terrible thing, but would have to be done often enough to keep your version of the data up to date.I strongly suggest storing it in an sql database like mysql. A single database table is the equivalent of a spreadsheet, and can be exported into csv or tsv format, which Excel can easily read. You can go back and forth with it that way also.The advantage to sql is it simplifies the process of extracting data from the table. There are libraries out there that will let PHP interface directly with Excel documents, but I have not used them.Either way, your server needs to write the spreadsheet data into your document. If it's between, say 10K and 100K, the best bet might be to hardcode all of it into JavaScript objects that live in the script section of your document. JavaScript can update select elements as needed (if needed) and fetch the correct train, or whatever, based on data chosen by the user.I suppose the select elements themselves can be hardcoded as HTML if they do not have to be dynamic. (By dynamic, I thinking of a gadget where choosing an option in one select element causes another select element to update its contents.)If the data exceeds 100K, then it might be more efficient to hardcode a minimal amount in your document, and then use forms or ajax to fetch results. Your server scripts will do the heavy lifting.Whichever way you go, I strongly suggest working with scaled-down test documents before you go all out. Don't even think about making the page pretty at this point. Work with dummy data maybe four rows long. Stay away from "wouldn't it be nice if . . ." kind of thoughts until you have the basic functionality down pat.If you are still at the level of Excel documents, be prepared to spend hours and hours developing this thing. More if your programming skills need sharpening.

Link to comment
Share on other sites

If you have internal access to metrorail's database, that would be ideal.
It looks to me like they don't have a database to begin with, but rather, than they're just plainly editing HTML files (maybe, just maybe, with an HTML editor or something).Well, if you decide to screensrap the data and have PHP, I suggest you do it with a Tidy + XPath combo, i.e. something like
<?php$file = 'http://www.capemetrorail.co.za/_timetables/20060402/south/flats-down.htm';$tidy = new tidy();$dom = new DOMDocument();$dom->loadXML($tidy->repairFile($file));$xpath = new DOMXPath($dom);//The next line would depend entirely on what exactly you want to do with the data.//In this case, the script should just output "05:02"echo $xpath->query('//td[. = "CAPE TOWN"][5]')->item(0)->nextSibling->nodeValue;?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...