Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] 2 small questions... From: Richard Lynch (lynch <email protected>)
Date: 03/17/99

At 2:43 PM 2/24/99, Mario Jorge Nunes Filipe wrote:

>I have a couple of questions to pose to the fine people who lurk (or is
>it lurke) arround this list.

lurk

>Number 1 - I want to produce a CSV file of a set of records from a
>database so that the users can import it into Excel (or similar). I
>would like to know if there is a way i can force the browser to show a
>file save dialog to save the file instead of showing the records on
>screen and forcing them to save.

Yes.
You'll want to have a link/form/whatever that leads to a separate php
script that does *NOT* spit out any HTML, nor blank lines, nor nothing, but
*DOES* spit out some headers, and then the "file" of CSV (you should also
consider tab-delimited) text.
Read the docs on Header() on www.php.net
Search the mailing list archives for "Content-Disposition" and make sure
the link/action actually has a URL with something like:

/path/to/script.php/filename.csv?whatever=whatever&something=something

The filename.csv is totally "bogus" as a URL goes: it is simply there to
make the Netscape browser think that it's downloading filename.csv

IE needs content-disposition, because, errr, it's IE.

>Number 2 - the very same files are going to be treated by the users and
>then re-imported to the system. Each line has a student number, the
>grade, and an adittional note. I read a line with fgets, then explode it
>using "," as the separator. There is a possibilitie that the first
>contains the headers instead of info, but it might not be there either.
>So i thought about testing the first field by doing is_int($dados[0]).
>$dados[0] is an integer (I insert into postgres on an int field and it
>doesn't complain) but is_int returns nothing and neither does is_string
>! So the question is : am i using is_int wrongly or is this pure and
>simply broken (unlikely?)?

If you fgets it from a file, it is a string that just happens to look like
an integer. You then feed it to postgres, without apostrophes, in your
sql, which tells it to treat it as an int.

I have no rational explanation for why is_string($dados[0]) did not return
true. Post source code if you can't figure it out.

-- "TANSTAAFL" Rich lynch <email protected> webmaster@ and www. all of:
R&B/jazz/blues/rock - jademaze.com music industry org - chatmusic.com
acoustic/funk/world-beat - astrakelly.com sculptures - olivierledoux.com
my own nascent company - l-i-e.com cool coffeehouse - uncommonground.com

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3
List administrator:  zeev-list-admin <email protected>