[PHP] Re: CSV download

2004-02-18 Thread John Herren
Mark Roberts wrote:

I have an application that I need to add a function to that will download a complete MySql Table in comma delineated format from a web site to a local hard drive.  What is the best way to do this?
 
Is there a function in PHP that will do this? in MySql? or do I just need to do something with fopen().
 
Anything to help me get started would be appreciated.

Mark Roberts 
Sr. Systems Analyst 

 

Here's a function I've used to spit out csv files. You can modify it to 
actually write the csv file to a directory. I use this function to build 
those files on the fly because I never need to save them. Pass the 
function your mysql query and a default filename that a user will save 
the file as. Also you'll need to connect to the database before you call 
the function.

function mysql_export_csv($query,$filename) {
header(Content-Type: text/csv);
header(Content-Disposition: attachment; filename=.$filename);
$result = mysql_query($query) or die( mysql_error() );
$number_cols = mysql_num_fields($result);
for ($i=0; $i  $number_cols; $i++) {
if ($i) echo ,;   /*  Insert 
comma before next field only
*   if not 
on the first column
*/
echo\ . mysql_field_name($result, $i). \;
}
echo \n;

while($row = mysql_fetch_array($result)) {
for ($i=0; $i  $number_cols; $i++) {
if ($i) echo ,;   /* 
 Insert comma before next field only
* 
 if not on the first column
*/
if (($row[$i]) == NULL) {
// Do nothing
} else if ($row[$i] === 0) {  /* === 
operand verifies type and value */
echo \0\;
} else if ($row[$i] === 0) {/* === 
operand verifies type and value */
echo \0\;
} else if ($row[$i] === ) {   /* === 
operand verifies type and value */
echo \\;
} else {
/** I get here it's not an 
empty string and it's not a zero;
*   otherwise, if I don't 
check... $values do not print if they are zero
*/
echo\ 
.str_replace(\,\\,$row[$i]). \;
}
}
echo \n;
}

}

to use:

mysql_export_csv($MyQuery,MyReport.csv);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] An HTML alternative to submit button to look like anchor??

2004-02-17 Thread John Herren
If you do this, make sure you name your submit button Submit or 
something else, but not submit :)

Shaunak Kashyap wrote:
Yes, you can use elementary javascript to achieve that goal.

Just make a link (anchor) as you normally would and make the value of its
href attribute javascript:document.formName.submit() where formName is the
name of the form you wish to submit. As with a lot of client-side scripting
languages, I cannot guarantee that this solution is cross-browser
compatible.
Shaunak
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: auto increment

2004-02-17 Thread John Herren
Marc Serra wrote:
Hi,

 

i use PEAR DB with a mysql database and i want to know if there is a
solution to get last inserted id in a table.
I see that I can use sequences but it doesn't work with mysql.

 

Thanks,

 

Marc.

Check this out:

http://pear.php.net/manual/en/package.database.db.intro-sequences.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] High bandwidth application tips

2003-11-05 Thread John Herren
Jay Blanchard wrote:

[snip]

limit the number of times you need to hit the database.

I second Chris on this.
[/snip]
I third that. The problem can become especially apparent in large
databases containing millions of records. Other than that just code
cleanly and document, document, document.
Creating indexes on columns that appear in your WHERE clauses can 
drastically increase performance when hitting the database. Be sure to 
read your database documentation on creating indexes.

A simple example of this would be a forgot your password script that 
emailed a user based on the user's email address. By indexing the email 
address field, your query will run much faster than without the index, 
and if you have several thousand records in your table, you will surely 
notice the difference.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Php processor and return window

2003-11-05 Thread John Herren
Robb Kerr wrote:

I am just learning PhP. When I was teaching myself Lingo (Macromedia
Director's programming language) I found an object called the MESSAGE
window quite helpful. This window allowed you to execute little snippets of
code and get the results without having to execute your entire script. For
instance, you could create a variable and give it a value then run an
if/then statement or loop on it and quickly see the results. This is quite
convenient when you're learning the language because you can test your
syntax line-by-line instead of having the whole script fail and not knowing
exactly where the error occurred.
Does anyone know about anything like this for PhP?

Thanx,
Give phpIDE a shot. It's nice for quick and dirty snippet testing. It's 
best run from a local apache/php installation, but you can run it 
remotely ONLY if you secure it.

http://www.ekenberg.se/php/ide/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Finally, PDF Header for PDF stuffs that work....

2003-10-16 Thread John Herren
OK, here's a different problem.

If I call a pdf file directly, the Acrobat plugin begins to display the 
file almost immediately. Here is the reponse header for calling the file 
directly:

HTTP/1.1 200 OK
Date: Thu, 16 Oct 2003 20:41:28 GMT
Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux) mod_ssl/2.8.12 
OpenSSL/0.9.6b PHP/4.3.3 mod_perl/1.26
X-Meta-MSSmartTagsPreventParsing: TRUE
X-MSSmartTagsPreventParsing: TRUE
Last-Modified: Thu, 16 Oct 2003 17:08:17 GMT
ETag: 94174-341fcb-3f8ed081
Accept-Ranges: bytes
Content-Length: 3416011
Connection: close
Content-Type: application/pdf

I wrote a pdf-serving script for anti-leech purposes, and it works fine, 
except that the acrobat plugin waits for the entire file to come down 
the pipe before anything is displayed. The mystery for me is that the 
headers--the important ones anyway--look exactly the same. Dig:

HTTP/1.1 200 OK
Date: Thu, 16 Oct 2003 20:44:45 GMT
Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux) mod_ssl/2.8.12 
OpenSSL/0.9.6b PHP/4.3.3 mod_perl/1.26
X-Meta-MSSmartTagsPreventParsing: TRUE
X-MSSmartTagsPreventParsing: TRUE
X-Powered-By: PHP/4.3.3
X-Accelerated-By: PHPA/1.3.3r2
Accept-Ranges: bytes
Content-Length: 3416011
Connection: close
Content-Type: application/pdf

Here's what's serving the file:

header(Content-Type: application/pdf);
header(Accept-Ranges: bytes);
header(Content-Length: .filesize($thefile));
readfile($thefile);
Can anybody tell me why the browser is waiting for the entire file 
before it's displayed(using php)? I don't think the average user will 
have the patience to stare at a blank browser waiting for the file.

Thanks!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Finally, PDF Header for PDF stuffs that work....

2003-10-16 Thread John Herren
Curt Zirzow wrote:

* Thus wrote John Herren ([EMAIL PROTECTED]):

header(Content-Type: application/pdf);
header(Accept-Ranges: bytes);
header(Content-Length: .filesize($thefile));
readfile($thefile);
Can anybody tell me why the browser is waiting for the entire file 
before it's displayed(using php)? I don't think the average user will 
have the patience to stare at a blank browser waiting for the file.


This is a pdf issue I believe. There is an option in the PDF called
'Fast Web View', if this is set adobe doesn't need to read the
whole thing before starting to view.
Check the pdf's 'Document properties' and You'll see if the option
is set or not.  If not, resave the document enabling that option.
Acrobat 5 has a nice little batch thing to convert serveral
docuements into this mode.
HTH,

Curt
I appreciate that advice. And Fast Web View is disabled. But I still 
don't understand why calling the file directly gives immediate output, 
but if I generate the headers and readfile() the file to the browser 
(same exact file) it waits to get the whole file.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Opening Zip Files in Linux

2003-09-05 Thread John Herren
John Ryan wrote:
This is kinda off topic, well.. depending on the answer.

I downloaded a ZIP file to my server, and want to open it. My version of PHP
wasnt compiled with the Zip uncompressing functions, otherwise Id do it with
php,  so I was wondering if there was a linux-x86 binary that just opens zip
files!
Try unzip :)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: controlling winamp with COM

2003-07-22 Thread John Herren
John Herren wrote:
Is there any way to control an open winamp application in php? I want to 
use php as a scheduler to play Winamp. The API has system calls to do 
so, but I don't know how to implement the windows calls.

Ok, found this:

http://www.adcock8.freeserve.co.uk/winamp.htm

It's a plugin that makes Winamp listen for COM calls, but I was having 
trouble getting it working. I've decided the best way to accomplish my 
goal is to create a C++ executable that can call the winamp API 
messages. And then I'll make PHP call that executable with switches. NOt 
a very elegant solution, but hey...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] regex help?

2003-07-21 Thread John Herren
Can't seem to get this to work...

trying to yank stuff xxx from
TD class=a8b noWrap align=middle width=17 bgColor=#ccxxx/TD
and stuff yyy from

TD class=a8b noWrap width=100nbsp;yyy/TD

preg_match(nbsp;(.*)/TD$|i, $l, $regs);

works for the second example, even though it isn't the correct way, but 
nothing works for for me for the first example.

Any help is appreciated!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] regex help?

2003-07-21 Thread John Herren
Can't seem to get this to work...

trying to yank stuff xxx from
TD class=a8b noWrap align=middle width=17 bgColor=#ccxxx/TD
and stuff yyy from

TD class=a8b noWrap width=100nbsp;yyy/TD

preg_match(|nbsp;(.*)/TD$|i, $l, $regs);

works for the second example, even though it isn't the correct way, but 
nothing works for for me for the first example.

Any help is appreciated!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] controlling winamp with COM

2003-07-21 Thread John Herren
Is there any way to control an open winamp application in php? I want to 
use php as a scheduler to play Winamp. The API has system calls to do 
so, but I don't know how to implement the windows calls.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php