473,797 Members | 3,199 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

from form to .csv file to webpage help req.

HI,
I have set up a page with a form which appends data to a .csv file on my asp
server, this is to enable a limited number of users to add news threads to
this file, which contains the data in the following format
(date,headline, article);
"181003","n ews title","news article"
"171003","o lder news title","news article"
The form adds the data in reverse chronological order with newest at the top
of the list.
Now I wish to be able to write the contents of the csv file to a table cell,
formatted the same as the rest of the page (if I use the include tag I get
unformatted text and all the speach marks and no paragraph tag in between
items).
I am new to javascript and asp, although I do have a basic understanding of
how they work.
Could someone kindly explain the best way to achieve this, I'm not looking
for someone to do my hard work for me nessacerely, if it isn't possible to
show me the coding needed, just an explanation will help greatly.
Many thanks in advance
StumpY
Jul 20 '05 #1
14 5434
Fox


StumpY wrote:

HI,
I have set up a page with a form which appends data to a .csv file on my asp
server, this is to enable a limited number of users to add news threads to
this file, which contains the data in the following format
(date,headline, article);
"181003","n ews title","news article"
"171003","o lder news title","news article"
The form adds the data in reverse chronological order with newest at the top
of the list.
Now I wish to be able to write the contents of the csv file to a table cell,
formatted the same as the rest of the page (if I use the include tag I get
unformatted text and all the speach marks and no paragraph tag in between
items).
I am new to javascript and asp, although I do have a basic understanding of
how they work.
Could someone kindly explain the best way to achieve this, I'm not looking
for someone to do my hard work for me nessacerely, if it isn't possible to
show me the coding needed, just an explanation will help greatly.
Many thanks in advance
StumpY


http://groups.google.com/groups?hl=e...tel.net&rnum=9
Jul 20 '05 #2
N1 - is there any way to automate this procedure? I want my users to have
as little 'access' to the site as possible.
Cheers for the reply

"Fox" <fo*@fxmahoney. com> wrote in message
news:3F******** *******@fxmahon ey.com...


StumpY wrote:

HI,
I have set up a page with a form which appends data to a .csv file on my asp server, this is to enable a limited number of users to add news threads to this file, which contains the data in the following format
(date,headline, article);
"181003","n ews title","news article"
"171003","o lder news title","news article"
The form adds the data in reverse chronological order with newest at the top of the list.
Now I wish to be able to write the contents of the csv file to a table cell, formatted the same as the rest of the page (if I use the include tag I get unformatted text and all the speach marks and no paragraph tag in between items).
I am new to javascript and asp, although I do have a basic understanding of how they work.
Could someone kindly explain the best way to achieve this, I'm not looking for someone to do my hard work for me nessacerely, if it isn't possible to show me the coding needed, just an explanation will help greatly.
Many thanks in advance
StumpY


http://groups.google.com/groups?hl=e...tel.net&rnum=9
Jul 20 '05 #3
Hi,

StumpY wrote:
N1 - is there any way to automate this procedure? I want my users to have
as little 'access' to the site as possible.
Cheers for the reply

"Fox" <fo*@fxmahoney. com> wrote in message
news:3F******** *******@fxmahon ey.com...

StumpY wrote:
HI,
I have set up a page with a form which appends data to a .csv file on my
asp
server, this is to enable a limited number of users to add news threads
to
this file, which contains the data in the following format
(date,headli ne,article);
"181003","ne ws title","news article"
"171003","ol der news title","news article"
The form adds the data in reverse chronological order with newest at the
top
of the list.
Now I wish to be able to write the contents of the csv file to a table
cell,
formatted the same as the rest of the page (if I use the include tag I
get
unformatte d text and all the speach marks and no paragraph tag in
between
items).
I am new to javascript and asp, although I do have a basic understanding
of
how they work.
Could someone kindly explain the best way to achieve this, I'm not
looking
for someone to do my hard work for me nessacerely, if it isn't possible
to
show me the coding needed, just an explanation will help greatly.
Many thanks in advance
StumpY


http://groups.google.com/groups?hl=e...tel.net&rnum=9


Fox didn't see that you have ASP, so what you're looking for is a
server-side solution.

On ASP, the procedure would be to:

1) Load the text file, using the FileSystemObjec t.
2) For each line, split the line in fields in a JavaScript array, using
the method strLine.split( "," ); where strLine is the line read form the
text file.
3) Build your table using the array's fields in a string.
4) Pass the built string in the Response object, like:
Response.Write( strHtml );

If you have troubles implementing this, ask me and I can provide you
with a small example.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #4
Fox


StumpY wrote:

N1 - is there any way to automate this procedure? I want my users to have
as little 'access' to the site as possible.
Cheers for the reply
The following is OffTopic

Use PHP -- it has a function specifically designed to read csv files.

<?php

// need to get how many records in file
// if your data file uses column labels
// remember to "burn off" the first record!
// this example ASSUMES your csv looks like:

// date,headline,a rticle => column labels
// "181003","n ews title","news article"
// "171003","o lder news title","news article"
function
getNumRecords($ h)
{
$cnt = -1; // discount column label row
// otherwise $cnt = 0;

while(fgetcsv($ h, 10000)) $cnt++;
rewind($h); // reset file pointer to beginning
return $cnt;
}

$handle = fopen("myNews.c sv","r");

$cnt = getNumRecords($ handle);

echo "<script>\n \n";
echo "var newsdata = [\n\t\t";

fgetcsv($handle , 10000); // burn off labels

for($i = 0; $i < $cnt; $i++)
{
$data = fgetcsv($handle , 10000);
$cols = count($data);
echo "[";

for($j = 0; $j < $cols; $j++)
echo "\"" . $data[$j] . "\"" . ($j < $cols-1 ? "," : "");

echo "]" . ($i < $cnt - 1 ? "," : "") . "\n\t\t";
}

echo "];\n\n";
echo "</script>";

?>
The output from this will look like:

<script>

var newsdata = [
["181003","n ews title","news article"],
["171003","o lder news title","news aritcle"]
];
</script>
This PHP script does basically the same thing as the form routine I
linked you to.

The function fgetcsv takes care of stripping the quotes from "cell"
entries containing commas and the number of entries is correctly
returned -- no special handling should be needed [I'm not sure what
happens with quotes used in the data -- you'll probably need to
experiment with that [but I wouldn't be surprised if the function took
care of escaping it for you].

The arguments to fgetcsv are (obviously) the reference returned from
fopen and the *length* of the line to be returned -- note, the length
MUST be greater than the total number of characters in the longest line
within the file if you expect to retrieve all your data.



"Fox" <fo*@fxmahoney. com> wrote in message
news:3F******** *******@fxmahon ey.com...


StumpY wrote:

HI,
I have set up a page with a form which appends data to a .csv file on my asp server, this is to enable a limited number of users to add news threads to this file, which contains the data in the following format
(date,headline, article);
"181003","n ews title","news article"
"171003","o lder news title","news article"
The form adds the data in reverse chronological order with newest at the top of the list.
Now I wish to be able to write the contents of the csv file to a table cell, formatted the same as the rest of the page (if I use the include tag I get unformatted text and all the speach marks and no paragraph tag in between items).
I am new to javascript and asp, although I do have a basic understanding of how they work.
Could someone kindly explain the best way to achieve this, I'm not looking for someone to do my hard work for me nessacerely, if it isn't possible to show me the coding needed, just an explanation will help greatly.
Many thanks in advance
StumpY


http://groups.google.com/groups?hl=e...tel.net&rnum=9

Jul 20 '05 #5
Cheers Fox - but I've got no PHP feature available (MS Hosting)
Stumpy
"Fox" <fo*@fxmahoney. com> wrote in message
news:3F******** ******@fxmahone y.com...


StumpY wrote:

N1 - is there any way to automate this procedure? I want my users to have as little 'access' to the site as possible.
Cheers for the reply


The following is OffTopic

Use PHP -- it has a function specifically designed to read csv files.

<?php

// need to get how many records in file
// if your data file uses column labels
// remember to "burn off" the first record!
// this example ASSUMES your csv looks like:

// date,headline,a rticle => column labels
// "181003","n ews title","news article"
// "171003","o lder news title","news article"
function
getNumRecords($ h)
{
$cnt = -1; // discount column label row
// otherwise $cnt = 0;

while(fgetcsv($ h, 10000)) $cnt++;
rewind($h); // reset file pointer to beginning
return $cnt;
}

$handle = fopen("myNews.c sv","r");

$cnt = getNumRecords($ handle);

echo "<script>\n \n";
echo "var newsdata = [\n\t\t";

fgetcsv($handle , 10000); // burn off labels

for($i = 0; $i < $cnt; $i++)
{
$data = fgetcsv($handle , 10000);
$cols = count($data);
echo "[";

for($j = 0; $j < $cols; $j++)
echo "\"" . $data[$j] . "\"" . ($j < $cols-1 ? "," : "");

echo "]" . ($i < $cnt - 1 ? "," : "") . "\n\t\t";
}

echo "];\n\n";
echo "</script>";

?>
The output from this will look like:

<script>

var newsdata = [
["181003","n ews title","news article"],
["171003","o lder news title","news aritcle"]
];
</script>
This PHP script does basically the same thing as the form routine I
linked you to.

The function fgetcsv takes care of stripping the quotes from "cell"
entries containing commas and the number of entries is correctly
returned -- no special handling should be needed [I'm not sure what
happens with quotes used in the data -- you'll probably need to
experiment with that [but I wouldn't be surprised if the function took
care of escaping it for you].

The arguments to fgetcsv are (obviously) the reference returned from
fopen and the *length* of the line to be returned -- note, the length
MUST be greater than the total number of characters in the longest line
within the file if you expect to retrieve all your data.



"Fox" <fo*@fxmahoney. com> wrote in message
news:3F******** *******@fxmahon ey.com...


StumpY wrote:
>
> HI,
> I have set up a page with a form which appends data to a .csv file
on my asp
> server, this is to enable a limited number of users to add news
threads to
> this file, which contains the data in the following format
> (date,headline, article);
> "181003","n ews title","news article"
> "171003","o lder news title","news article"
> The form adds the data in reverse chronological order with newest at
the top
> of the list.
> Now I wish to be able to write the contents of the csv file to a
table cell,
> formatted the same as the rest of the page (if I use the include tag
I get
> unformatted text and all the speach marks and no paragraph tag in

between
> items).
> I am new to javascript and asp, although I do have a basic
understanding of
> how they work.
> Could someone kindly explain the best way to achieve this, I'm not

looking
> for someone to do my hard work for me nessacerely, if it isn't
possible to
> show me the coding needed, just an explanation will help greatly.
> Many thanks in advance
> StumpY

http://groups.google.com/groups?hl=e...tel.net&rnum=9
Jul 20 '05 #6
Hi Laurent,

a small example would be absolutely blinding :)

Cheers for your help

Stumpy

"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
message news:3f******** @news.bluewin.c h...
Hi,

StumpY wrote:
N1 - is there any way to automate this procedure? I want my users to have as little 'access' to the site as possible.
Cheers for the reply

"Fox" <fo*@fxmahoney. com> wrote in message
news:3F******** *******@fxmahon ey.com...

StumpY wrote:

HI,
I have set up a page with a form which appends data to a .csv file on
my
asp
server, this is to enable a limited number of users to add news threads
to
this file, which contains the data in the following format
(date,headli ne,article);
"181003","ne ws title","news article"
"171003","ol der news title","news article"
The form adds the data in reverse chronological order with newest at
the
top
of the list.
Now I wish to be able to write the contents of the csv file to a table


cell,
formatted the same as the rest of the page (if I use the include tag I


get
unformatte d text and all the speach marks and no paragraph tag in


between
items).
I am new to javascript and asp, although I do have a basic
understanding
of
how they work.
Could someone kindly explain the best way to achieve this, I'm not


looking
for someone to do my hard work for me nessacerely, if it isn't possible


to
show me the coding needed, just an explanation will help greatly.
Many thanks in advance
StumpY

http://groups.google.com/groups?hl=e...tel.net&rnum=9
Fox didn't see that you have ASP, so what you're looking for is a
server-side solution.

On ASP, the procedure would be to:

1) Load the text file, using the FileSystemObjec t.
2) For each line, split the line in fields in a JavaScript array, using
the method strLine.split( "," ); where strLine is the line read form the
text file.
3) Build your table using the array's fields in a string.
4) Pass the built string in the Response object, like:
Response.Write( strHtml );

If you have troubles implementing this, ask me and I can provide you
with a small example.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #7
Hi,

StumpY wrote:
Hi Laurent,

a small example would be absolutely blinding :)

Cheers for your help

Stumpy


Here is a very simple example. You can modify the table layout in the
line 24 and following.

HTH,

Laurent

----------------------------
<%@Language=Jav aScript %>

<HTML>
<HEAD>
<TITLE>GalaSoft </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFF F">

<%

var NAME_CSV_FILE = "d:\\temp\\test .txt";

var fso = Server.CreateOb ject( "Scripting.File SystemObject" );

if ( !fso.FileExists ( NAME_CSV_FILE ) )
{
Response.Write( "The file doesn't exist" );
}
else
{
// 1 = ForReading
var fl = fso.OpenTextFil e( NAME_CSV_FILE, 1 );

var strTable = "<TABLE BORDER='1'>\n";

while ( !fl.AtEndOfStre am )
{
var strLine = fl.ReadLine();
var astrLine = strLine.split( ',' );

// Remove "" from fields
var strDate
= astrLine[0].substring( 1, astrLine[0].length - 1 );
var strTitle
= astrLine[1].substring( 1, astrLine[1].length - 1 );
var strArticle
= astrLine[2].substring( 1, astrLine[2].length - 1 );

var strTableRow = "<TR>\n"
+ "<TD>" + strDate + "</TD>\n"
+ "<TD>" + strTitle + "</TD>\n"
+ "<TD>" + strArticle + "</TD>\n"
+ "</TR>\n";

strTable += strTableRow;
}

strTable += "</TABLE>\n";

Response.Write( strTable );
}

%>

</BODY>
</HTML>

--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #8
Hi,

StumpY wrote:
Cheers Fox - but I've got no PHP feature available (MS Hosting)
Stumpy


You could install PHP on your host, solutions are available AFAIK.
However, if you have a MS host anyway, you're better off with ASP and
JScript.

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #9
Thank you very much - a lifesaver!!

"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
message news:bm******** **@rex.ip-plus.net...
Hi,

StumpY wrote:
Hi Laurent,

a small example would be absolutely blinding :)

Cheers for your help

Stumpy


Here is a very simple example. You can modify the table layout in the
line 24 and following.

HTH,

Laurent

----------------------------
<%@Language=Jav aScript %>

<HTML>
<HEAD>
<TITLE>GalaSoft </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFF F">

<%

var NAME_CSV_FILE = "d:\\temp\\test .txt";

var fso = Server.CreateOb ject( "Scripting.File SystemObject" );

if ( !fso.FileExists ( NAME_CSV_FILE ) )
{
Response.Write( "The file doesn't exist" );
}
else
{
// 1 = ForReading
var fl = fso.OpenTextFil e( NAME_CSV_FILE, 1 );

var strTable = "<TABLE BORDER='1'>\n";

while ( !fl.AtEndOfStre am )
{
var strLine = fl.ReadLine();
var astrLine = strLine.split( ',' );

// Remove "" from fields
var strDate
= astrLine[0].substring( 1, astrLine[0].length - 1 );
var strTitle
= astrLine[1].substring( 1, astrLine[1].length - 1 );
var strArticle
= astrLine[2].substring( 1, astrLine[2].length - 1 );

var strTableRow = "<TR>\n"
+ "<TD>" + strDate + "</TD>\n"
+ "<TD>" + strTitle + "</TD>\n"
+ "<TD>" + strArticle + "</TD>\n"
+ "</TR>\n";

strTable += strTableRow;
}

strTable += "</TABLE>\n";

Response.Write( strTable );
}

%>

</BODY>
</HTML>

--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
6146
by: Pete..... | last post by:
Hi all. I have made a webpage where there is a webform where people can fill in their personel information: The code is below: I want to transfer the data to a postgreSQL database ( I have allready made the database with the neccesary tables, and I know how to connect to it ) but I really have no idea how I can transfer the data from the webform to
5
5719
by: NK | last post by:
Hi, We have a webpage that has a form available on the intranet. A user will have a window open that runs a different application open. When the user accesses the webpage and clicks a button we should capture the data from the application window and populate the form. Is it possible to access text inside another opened window on the client pc, using javascript?
1
8043
by: teknowbabble | last post by:
I would like to know how to convert HTML code that users input into a TEXTAREA box on a HTML FORM into a separate WEBPAGE. I have something like the diagram below on my webpage. The user is prompted to input his/her HTML Code in the FORM TEXTAREA. By pushing the Make Webpage Button, a new window opens with the output of the HTML contents they inputted. This way people can see what their HTML looks like. HTML FORM TEXTAREA (Where user...
6
11304
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header" Src="WebControls/Header.ascx" %> The web user control contains the following server controls
5
18308
by: John Bradley | last post by:
Toooo tired to look this one up. I have data that I need to acces in a small program. The data is accessable from an ASP webpage that I created myself. If I need to see data from record #25, I just open http://mydomain.com/datapage.asp?recnum=25. I would like to read this data directly into a variable. I'm sure this is quite easy (as easy as Fileopen), but I just can't seem to find it.
10
23397
by: sanou | last post by:
Hi does anyone know if the following is possible? I have an excel spreadsheet with values that i need transferred to a certain website's form. for instance, i have a value in excel spreadsheet xyz that i wanted to transfer to a data entry box on a webpage that is concurrently open. basically i want to make it simple enough that at a push of a button, i can copy/paste all my data into another form. alternatively, i guess could have a...
6
2880
by: shivavrata | last post by:
Hi All, I want to transfer the data form webpage to any other own application which is running in backend.How i develop this web page. which technology is good for this or any particular protocol i have to use for this. Please suggest if any idea regarding data transfer. Thanks Shiva Vrata Anand
5
2756
by: Orv | last post by:
I have a database set up where I want to export the records to a cd. I want to be able to create an autorun cd and have it based on HTML so when it opens, the user can click on various links and it will show them the corresponding record. Any ideas? A template or merge would be great as not all the records from the DB would be going on the CD. TIA,
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10469
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10246
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.