Cheers Fox - but I've got no PHP feature available (MS Hosting)
Stumpy
"Fox" <fox@fxmahoney.com> wrote in message
news:3F925728.1999C6F@fxmahoney.com...[color=blue]
>
>
> StumpY wrote:[color=green]
> >
> > N1 - is there any way to automate this procedure? I want my users to[/color][/color]
have[color=blue][color=green]
> > as little 'access' to the site as possible.
> > Cheers for the reply[/color]
>
> 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,article => column labels
> // "181003","news title","news article"
> // "171003","older 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.csv","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","news title","news article"],
> ["171003","older 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.
>
>
>
>
>
>
>[color=green]
> >
> > "Fox" <fox@fxmahoney.com> wrote in message
> > news:3F91ED96.F470B72C@fxmahoney.com...[color=darkred]
> > >
> > >
> > > StumpY wrote:
> > > >
> > > > HI,
> > > > I have set up a page with a form which appends data to a .csv file[/color][/color][/color]
on my[color=blue][color=green]
> > asp[color=darkred]
> > > > server, this is to enable a limited number of users to add news[/color][/color][/color]
threads[color=blue][color=green]
> > to[color=darkred]
> > > > this file, which contains the data in the following format
> > > > (date,headline,article);
> > > > "181003","news title","news article"
> > > > "171003","older news title","news article"
> > > > The form adds the data in reverse chronological order with newest at[/color][/color][/color]
the[color=blue][color=green]
> > top[color=darkred]
> > > > of the list.
> > > > Now I wish to be able to write the contents of the csv file to a[/color][/color][/color]
table[color=blue][color=green]
> > cell,[color=darkred]
> > > > formatted the same as the rest of the page (if I use the include tag[/color][/color][/color]
I[color=blue][color=green]
> > get[color=darkred]
> > > > unformatted text and all the speach marks and no paragraph tag in[/color]
> > between[color=darkred]
> > > > items).
> > > > I am new to javascript and asp, although I do have a basic[/color][/color][/color]
understanding[color=blue][color=green]
> > of[color=darkred]
> > > > how they work.
> > > > Could someone kindly explain the best way to achieve this, I'm not[/color]
> > looking[color=darkred]
> > > > for someone to do my hard work for me nessacerely, if it isn't[/color][/color][/color]
possible[color=blue][color=green]
> > to[color=darkred]
> > > > show me the coding needed, just an explanation will help greatly.
> > > > Many thanks in advance
> > > > StumpY
> > >
> > >[/color]
> >[/color][/color]
http://groups.google.com/groups?hl=e...tel.net&rnum=9