|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
HI everyone,
I think I'm getting closer to understanding functions, but I'm blanking on how to fix a problem that I have... I am attempting to export a database to excel, which was working before converting the code into a function. What's happening is, I have the code set and it downloads the file into excel, but it doesn't have the database fields in it, rather a copy of the entire webpage which it trys to put into excel. Below is the code that I am using in my function to export the records: <?PHP function excelexportfunc($select, $sortOrder, $exportdate) { $export = mysql_query($select); $fields = mysql_num_fields($export); for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . "\t"; } while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) or ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line). "\n"; } $data = str_replace("\r", "", $data); if ($data =="") { $data ="\n(0) Records Found!\n"; } header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=Export.". $exportdate.".xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; } ?> I am calling the function like so: "excelexportfunc($select, $sortOrder, $exportdate);" the $select is specified in an IF statement on the calling page like so: if($exportoption =="all"){ $sortOrder= $_SESSION['order']; $search = ""; $select = "SELECT * FROM ".$table." order by ".$sortOrder.""; }else{ $sortOrder = $_SESSION['order']; $search = $_SESSION['search']; $select = "SELECT * FROM ".$table." WHERE FName like '%".$search."%' or LName like '%".$search."%' or Add1 like '%".$search."%' or Add2 like '%".$search."%' or City like '%".$search."%' or State like '%". $search."%' or Zip like '%".$search."%' or XCode like '%".$search."%' order by ".$sortOrder.""; } If anyone has any ideas I would love to hear about them. Hopefully it's just a simple "." in the wrong place! ![]() -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
OK I have tried e-mailing the PHP-Install mailing list and all I got in
response from that list was spam... So I thought I would try here. OK I am attempting to install PHP 5.2.5 on a new system here is what I have: SunOS server1 5.10 Generic_118833-24 sun4u sparc SUNW,Sun-Fire-V210 Here is the GCC version: gcc version 3.4.3 (csl-sol210-3_4-branch+sol_rpath) now when I run the ./configure I am doing a : ../configure --prefix=/opt/local/stow/php-5.2.5 --with-apxs2=/usr/local/httpd-2.2.8/bin/apxs --with-config-file-path=/usr/local/apache/conf Nothing special on that.. I was originally trying to do a: ../configure --prefix=/opt/local/stow/php-5.2.5 --with-apxs2=/usr/local/httpd-2.2.8/bin/apxs --enable-calendar --with-config-file-path=/usr/local/apache/conf --with-zlib --with-openssl=/opt/local/stow/openssl-0.9.8d --with-jpeg-dir=/opt/local/stow/jpeg-6b --with-png-dir=/opt/local/stow/libpng-1.2.5 --with-gd --enable-gd-native-ttf --with-ttf --with-xpm-dir=/opt/local/stow/xpm-3.4k-solaris --with-mysql=/opt/local/stow/mysql-5.0.51 But still nothing... Here is the error message: /bin/sh /export/home/UID/php-5.2.5/libtool --silent --preserve-dup-deps --mode=compile gcc -Imain/ -I/export/home/ UID /php-5.2.5/main/ -DPHP_ATOM_INC -I/export/home/UID/php-5.2.5/include -I/export/home/ UID /php-5.2.5/main -I/export/home/ UID /php-5.2.5 -I/usr/local/include/libxml2 -I/export/home/ UID /php-5.2.5/ext/date/lib -I/export/home/UID/php-5.2.5/TSRM -I/export/home/UID/php-5.2.5/Zend -D_POSIX_PTHREAD_SEMANTICS -I/usr/local/include -D_REENTRANT -c /export/home/UID/php-5.2.5/main/mergesort.c -o main/mergesort.lo /bin/sh /export/home/UID/php-5.2.5/libtool --silent --preserve-dup-deps --mode=compile gcc -Imain/ -I/export/home/UID/php-5.2.5/main/ -DPHP_ATOM_INC -I/export/home/UID/php-5.2.5/include -I/export/home/UID/php-5.2.5/main -I/export/home/UID/php-5.2.5 -I/usr/local/include/libxml2 -I/export/home/UID/php-5.2.5/ext/date/lib -I/export/home/UID/php-5.2.5/TSRM -I/export/home/UID/php-5.2.5/Zend -D_POSIX_PTHREAD_SEMANTICS -I/usr/local/include -D_REENTRANT -c /export/home/UID/php-5.2.5/main/reentrancy.c -o main/reentrancy.lo /export/home/UID/php-5.2.5/main/reentrancy.c: In function `php_ctime_r': /export/home/UID/php-5.2.5/main/reentrancy.c:63: error: too many arguments to function `ctime_r' /export/home/UID/php-5.2.5/main/reentrancy.c: In function `php_asctime_r': /export/home/UID/php-5.2.5/main/reentrancy.c:70: error: too many arguments to function `asctime_r' /export/home/UID/php-5.2.5/main/reentrancy.c: In function `php_readdir_r': /export/home/UID/php-5.2.5/main/reentrancy.c:139: error: too few arguments to function `readdir_r' make: *** [main/reentrancy.lo] Error 1 Can anyone suggest anything for me to try??? Thank you all for any you can give. Regards, William "Billy" A. Strader NAISMC Web Services Work: 865-425-5178 Pager: 865-417-5012 Emergency Pager: 865-417-5622 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Jan 29, 2008 11:07 AM, Jason Pruim <japruim@raoset.com> wrote:
> What's happening is, I have the code set and it downloads the file > into excel, but it doesn't have the database fields in it, rather a > copy of the entire webpage which it trys to put into excel. this sounds to me like you may not be linking to the code that generates the excel spreadsheet properly. this is just a hunch, but to test it, you might try pointing your browser directly at the script that generates the excel spreadsheet, rather than navigating to it via a link you have on your current page. as far as the data not showing up in the output, try experimenting by omitting the header() calls and just dump out the result set of the query to ensure the data is actually getting populated in your function. -nathan |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Jan 29, 2008, at 11:48 AM, Nathan Nobbe wrote: > On Jan 29, 2008 11:07 AM, Jason Pruim <japruim@raoset.com> wrote: > What's happening is, I have the code set and it downloads the file > into excel, but it doesn't have the database fields in it, rather a > copy of the entire webpage which it trys to put into excel. > > this sounds to me like you may not be linking to the code that > generates > the excel spreadsheet properly. this is just a hunch, but to test > it, you > might try pointing your browser directly at the script that > generates the > excel spreadsheet, rather than navigating to it via a link you have > on your > current page. > as far as the data not showing up in the output, try experimenting by > omitting the header() calls and just dump out the result set of the > query > to ensure the data is actually getting populated in your function. > > -nathan Well, I commented out the header lines and just printed the data to the browser, and it fills it all in perfectly. So I think you are right about not calling it right... I'll do some more checking on that, back to the $salt farms I go! ![]() -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Jan 29, 2008, at 11:58 AM, Jason Pruim wrote: > > On Jan 29, 2008, at 11:48 AM, Nathan Nobbe wrote: > >> On Jan 29, 2008 11:07 AM, Jason Pruim <japruim@raoset.com> wrote: >> What's happening is, I have the code set and it downloads the file >> into excel, but it doesn't have the database fields in it, rather a >> copy of the entire webpage which it trys to put into excel. >> >> this sounds to me like you may not be linking to the code that >> generates >> the excel spreadsheet properly. this is just a hunch, but to test >> it, you >> might try pointing your browser directly at the script that >> generates the >> excel spreadsheet, rather than navigating to it via a link you have >> on your >> current page. >> as far as the data not showing up in the output, try experimenting by >> omitting the header() calls and just dump out the result set of the >> query >> to ensure the data is actually getting populated in your function. >> >> -nathan > > Well, I commented out the header lines and just printed the data to > the browser, and it fills it all in perfectly. So I think you are > right about not calling it right... I'll do some more checking on > that, back to the $salt farms I go! ![]() Okay, so I checked everything I can think of, and it's still downloading it as an application which means it's downloading the entire website instead of just the data from the database... Anyone have any idea what to check? -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Jan 29, 2008 2:39 PM, Jason Pruim <japruim@raoset.com> wrote:
> Okay, so I checked everything I can think of, and it's still > downloading it as an application which means it's downloading the > entire website instead of just the data from the database... Anyone > have any idea what to check? im guessing youre trying to hit the invocation of excelexportfunc(), as it sits in your existing script. create a simple test script that does nothing else but invoke the excelexportfunc() function. you can pass variables to it from the url, or hardcode them if you like; id probly hardcode them at first. <?php include('excelexportfunc.php'); // <-- set accordingly $select = ''; // <-- set me $sortOrder = '' <-- set me $exportdate = '' <-- set me excelexportfunc($select, $sortOrder, $exportdate); ?> that *should* get you the results youre looking for. from there you need to determine why the method isnt working in the context of your existing script. -nathan |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Jan 29, 2008, at 2:46 PM, Nathan Nobbe wrote: > On Jan 29, 2008 2:39 PM, Jason Pruim <japruim@raoset.com> wrote: > Okay, so I checked everything I can think of, and it's still > downloading it as an application which means it's downloading the > entire website instead of just the data from the database... Anyone > have any idea what to check? > > im guessing youre trying to hit the invocation of excelexportfunc(), > as > it sits in your existing script. create a simple test script that > does nothing > else but invoke the excelexportfunc() function. you can pass > variables to > it from the url, or hardcode them if you like; id probly hardcode > them at first. > > <?php > include('excelexportfunc.php'); // <-- set accordingly > > $select = ''; // <-- set me > $sortOrder = '' <-- set me > $exportdate = '' <-- set me > > excelexportfunc($select, $sortOrder, $exportdate); > ?> > > that *should* get you the results youre looking for. from there you > need to > determine why the method isnt working in the context of your > existing script. > > -nathan Hey Nathan, I did as you suggested, and I think I found the reason... I included info for the doctype, and some files that are on all my pages... Once I comment out those lines it works just fine... I'm assuming that that is expected behavior? -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Jan 29, 2008 3:53 PM, Jason Pruim <japruim@raoset.com> wrote:
> I did as you suggested, and I think I found the reason... I included info > for the doctype, and some files that are on all my pages... Once I comment > out those lines it works just fine... > I'm assuming that that is expected behavior? > where did you include this information? i didnt see it in the original code you posted. and, btw. im no expert on setting mime types for excel ![]() -nathan |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
> What's happening is, I have the code set and it downloads the file into > excel, but it doesn't have the database fields in it, rather a copy of > the entire webpage which it trys to put into excel. Below is the code > that I am using in my function to export the records: > > <?PHP > function excelexportfunc($select, $sortOrder, $exportdate) { echo $select . "<br/>\n"; if you run that through your db manually do you get an error? > $export = mysql_query($select); var_dump($export); > $fields = mysql_num_fields($export); // initialize the header line to be an empty string. $header = ''; > for ($i = 0; $i < $fields; $i++) { > $header .= mysql_field_name($export, $i) . "\t"; > } You will need a trim here otherwise you'll have an extra empty column (extra \t in there): $header = trim($header); > while($row = mysql_fetch_row($export)) { > $line = ''; > foreach($row as $value) { > if ((!isset($value)) or ($value == "")) { > $value = "\t"; > } > else > { > $value = str_replace('"', '""', $value); > $value = '"' . $value . '"' . "\t"; > } > $line .= $value; > } > $data .= trim($line). "\n"; > } > $data = str_replace("\r", "", $data); > > if ($data =="") { > $data ="\n(0) Records Found!\n"; > } > > header("Content-type: application/vnd.ms-excel"); > header("Content-Disposition: attachment; > filename=Export.".$exportdate.".xls"); > header("Pragma: no-cache"); > header("Expires: 0"); > > > > print "$header\n$data"; Once you've printed out the report, you should probably exit so nothing else is processed from the script. > } > > ?> > > I am calling the function like so: "excelexportfunc($select, $sortOrder, > $exportdate);" > > the $select is specified in an IF statement on the calling page like so: > > if($exportoption =="all"){ > $sortOrder= $_SESSION['order']; > $search = ""; > $select = "SELECT * FROM ".$table." order by ".$sortOrder.""; > > }else{ > > $sortOrder = $_SESSION['order']; > $search = $_SESSION['search']; > $select = "SELECT * FROM ".$table." WHERE FName like > '%".$search."%' or LName like '%".$search."%' or Add1 like > '%".$search."%' or Add2 like '%".$search."%' or City like > '%".$search."%' or State like '%".$search."%' or Zip like > '%".$search."%' or XCode like '%".$search."%' order by ".$sortOrder.""; > } $sortOrder is now part of $select you don't need to pass it to the function unless you actually use it in that function (which from your copy/paste isn't the case). So your function can just be: function excelexportfunc($select, $exportdate) { and remove the $sortOrder from the calling lines: excelexportfunc($select, $exportdate); -- Postgresql & php tutorials http://www.designmagick.com/ |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
On Jan 29, 2008, at 4:29 PM, Nathan Nobbe wrote: > On Jan 29, 2008 3:53 PM, Jason Pruim <japruim@raoset.com> wrote: > I did as you suggested, and I think I found the reason... I included > info for the doctype, and some files that are on all my pages... > Once I comment out those lines it works just fine... > > I'm assuming that that is expected behavior? > > where did you include this information? > i didnt see it in the original code you posted. > and, btw. im no expert on setting mime types for excel ![]() > > -nathan > They were included in a config file I am working on... the defaults.php file that has other config info, such as DB auth info and system wide variables. -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
On Tue, January 29, 2008 1:39 pm, Jason Pruim wrote:
> Okay, so I checked everything I can think of, and it's still > downloading it as an application which means it's downloading the > entire website instead of just the data from the database... Anyone > have any idea what to check? Can you explain what you mean by "downloading it as an application"?... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
On Jan 30, 2008, at 7:53 PM, Richard Lynch wrote: > On Tue, January 29, 2008 1:39 pm, Jason Pruim wrote: >> Okay, so I checked everything I can think of, and it's still >> downloading it as an application which means it's downloading the >> entire website instead of just the data from the database... Anyone >> have any idea what to check? > > Can you explain what you mean by "downloading it as an > application"?... I can try when I downloaded in clicking on the link, and tried toopen it OS X popped on a message saying that I had downloaded an applicaiton and it was the first time I had tried to open it, was I sure that I wanted to, and I could view the web page it was downloaded from, go ahead and open it, or cancel. When I tell it to open, it opens in excel, what appears to be a copy of the actual webpage. Including the CSS, images, my banner, and then as much of the actual database at it can cram into 1 cell. What I found out though, is after I removed the doctype, and banners from an included file that I was able to download it as a normal excel file and now is working great. I hope that explains it a little better... And now, I just need to get my search function to work But that'sanother e-mail... We'll see if I get a chance to tackle it today or not. Thanks for looking though! Your replies have always been extremely ful. -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
2008. 01. 31, csütörtök keltezéssel 08.12-kor Jason Pruim ezt Ãrta:
> On Jan 30, 2008, at 7:53 PM, Richard Lynch wrote: > > > On Tue, January 29, 2008 1:39 pm, Jason Pruim wrote: > >> Okay, so I checked everything I can think of, and it's still > >> downloading it as an application which means it's downloading the > >> entire website instead of just the data from the database... Anyone > >> have any idea what to check? > > > > Can you explain what you mean by "downloading it as an > > application"?... > > > I can try when I downloaded in clicking on the link, and tried to> open it OS X popped on a message saying that I had downloaded an > applicaiton and it was the first time I had tried to open it, was I > sure that I wanted to, and I could view the web page it was downloaded > from, go ahead and open it, or cancel. > > When I tell it to open, it opens in excel, what appears to be a copy > of the actual webpage. Including the CSS, images, my banner, and then > as much of the actual database at it can cram into 1 cell. > > What I found out though, is after I removed the doctype, and banners > from an included file that I was able to download it as a normal excel > file and now is working great. oh yeah, never put your html&css stuff into an excel download ![]() greets Zoltán Németh > > I hope that explains it a little better... > > And now, I just need to get my search function to work But that's> another e-mail... We'll see if I get a chance to tackle it today or not. > > Thanks for looking though! Your replies have always been extremely > ful. > -- > > Jason Pruim > Raoset Inc. > Technology Manager > MQC Specialist > 3251 132nd ave > Holland, MI, 49424 > www.raoset.com > japruim@raoset.com > |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
On Jan 31, 2008, at 8:19 AM, Zoltán Németh wrote: >> >> >> I can try when I downloaded in clicking on the link, and tried to>> open it OS X popped on a message saying that I had downloaded an >> applicaiton and it was the first time I had tried to open it, was I >> sure that I wanted to, and I could view the web page it was >> downloaded >> from, go ahead and open it, or cancel. >> >> When I tell it to open, it opens in excel, what appears to be a copy >> of the actual webpage. Including the CSS, images, my banner, and then >> as much of the actual database at it can cram into 1 cell. >> >> What I found out though, is after I removed the doctype, and banners >> from an included file that I was able to download it as a normal >> excel >> file and now is working great. > > oh yeah, never put your html&css stuff into an excel download ![]() Yeah.. It wasn't intentional... Stupid include files... Try and manage the settings from 1 location and get hassled for doing it! :P Anyway, Now I just create a visual.include file for my doctype/banner type stuff ![]() -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |
|
![]() |
| Outils de la discussion | |
|
|