...

View Full Version : Is JavaScript the right language to use?



bigwillyco
05-21-2009, 09:06 PM
I need to pull data from a CSV file. The data is a list of names, the separator can be just about any character other than a comma (the name is the last name comma first initial), so I can add any other character.
I need to pull the data from this file, and display it on a web page. The data in the CSV file is along the first row in the spreadsheet but I want to be able to take this data and display in to columns.

*Like this*

Name1 Name2
Name3 Name4
Name5 Name6

So like the title says, is JavaScript able to do this?

If this is a function of JavaScript, could the script delete the reference file when it's done? The program I'm using to parse the data is a little retarded and this would help out.

nightwolfcem
05-21-2009, 11:17 PM
perhaps pull with ajax(ajax.open("GET","list.csv")) and text assing to a Array with text.split(",") than create table use this array .
reference file only be delete by server (delete.php?deletefile=list.csv)

Old Pedant
05-22-2009, 05:51 AM
What technology are you running on the server??? PHP? JSP? ASP?

How are you creating the CSV file? *WHERE* are you creating the CSV file?

Almost surely you would be better off using server-side technology to do this. And you might even then eliminate the need for the CSV file. You don't give us enough info to go on.

bigwillyco
05-22-2009, 06:02 PM
What technology are you running on the server??? PHP? JSP? ASP?

How are you creating the CSV file? *WHERE* are you creating the CSV file?

Almost surely you would be better off using server-side technology to do this. And you might even then eliminate the need for the CSV file. You don't give us enough info to go on.

So quick overview, I've got a really old system that nobody really knows how to reprogram. It interfaces with a really lame old display technology that nobody makes anymore and I've been told to modernize it. EZ right?

Long overview of the entire project.
I have a legacy system transmitting data over Telnet. The legacy system really cannot be modified (cost and coding is an issue). All it's doing is transmitting a string of data originally designed to communicate with an old LED display board. This data is retransmitted every 10 seconds or so. The company that manufactures those display boards went tits up and I've been tasked with attempting to find a way to make this work with a LCD TV or Monitor as the old display boards are slowly falling apart and parts are almost impossible to find.
I'm using Advanced TCP / IP Logger to capture and parse the data. There are several output methods available for me to use, text, CSV, XML, and even an HTML format. So far it's the only software I've found that will listen to the inbound port, capture, and parse the data. If anybody else has a suggestion for software, I'm willing to give it a try! The output from the software has been kicking my butt. The HTML portion would be great but the thing won't let me control the format of the output and it stacks the data if I use the same file name for out put. There is an ActiveX control for the software that I'm exploring but I'm so rusty on ActiveX that it's not funny. The support for the software is less than useful. The help files and documentation on use is laughable too.

I am running a EasyPHP 3.0.

bigwillyco
05-22-2009, 09:49 PM
Maybe I have been trying with the wrong file format.
I went ahead and switched to a .txt file with the data seperated by a dollar sign ($).

AAAAA,T $ $ $ $ $

The code I'm using to add everything to the array is below, but the LIST-Contents code I'm using isn't working. I assume I have something coded wrong :( I can get the data to post (just want to check to make sure it is parsing the data correctly) after I see the data posting correctly I will attempt to format everything.


<html>
<body>

<?PHP
$Data=file_get_contents('name14.txt');
$DataArray=explode("$",str_replace('\n','\n',$Data));
array_pop($DataArray);
$List=ProcessList($DataArray);
function ProcessList($Data)
{
function LIST_CONTENTS($DataArray,$tab=" ",$indent=0)
{
while(list($key, $value) = each($DataArray))
{
for($i=0; $i<$indent; $i++) $currenttab .= $tab;
if (is_array($value))
{
$retval .= "$currenttab$key : Array: <BR>$currenttab{<BR>";
$retval .= LIST_CONTENTS($value,$tab,$indent+1)."$currenttab}<BR>";
}
else $retval .= "$currenttab$key => $value<BR>";
$currenttab = NULL;
}
return $retval;
}
}
?>


</body>
</html>

The good news is, I get a blank page in my test environment (Yeah! No error codes!) bad news is, I was hoping to see AAAAAT,T

Old Pedant
05-22-2009, 09:52 PM
So I would do this 100% server-side, in PHP.

The PHP code can generate the HTML you need in the proper columnar format.

The PHP code can parse/reformat/rebuild whatever is needed to be done with the CSV or XML or whatever input.

If you need to delete files at some point in time (as they become obsolete because of new data???), the PHP can do it.

Almost no reason to use JavaScript for anything here, that I can see.

I am *NOT* a PHP person, but many people here are. (But I think even I could come up with the PHP needed for this simple project. But wouldn't guaranatee it.)

Having said all the above: You probably *could* do this without server-side help. But you mentioned "could the script delete the reference file when it's done?" and the answer to that is "no" when it comes to client-side JavaScript. So since you need *some* server-side coding, why not just do it all server-side?

Old Pedant
05-22-2009, 09:54 PM
Talk about timing...okay, no time to get this thread moved to the PHP forum.

Some of that code there makes no sense to me: For example:
str_replace('\n','\n',$Data)
HUH? Why would your replace a newline with a newline?

bigwillyco
05-22-2009, 10:08 PM
another programmer here recommened this to change out a charater return to make it constant.
I'm going to go ahead and close out this string and move it over to the PHP forum. Thanks for your help!
Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum