PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Another question about functions...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Another question about functions...

Réponse
 
LinkBack Outils de la discussion
Vieux 29/01/2008, 16h07   #1
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Another question about functions...

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



  Réponse avec citation
Vieux 29/01/2008, 16h13   #2
Strader, William A.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut PHP 5.2.5 Install Question/Problem

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
  Réponse avec citation
Vieux 29/01/2008, 16h48   #3
Nathan Nobbe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...

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

  Réponse avec citation
Vieux 29/01/2008, 16h58   #4
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...


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



  Réponse avec citation
Vieux 29/01/2008, 19h39   #5
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...


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
  Réponse avec citation
Vieux 29/01/2008, 19h46   #6
Nathan Nobbe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...

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

  Réponse avec citation
Vieux 29/01/2008, 20h53   #7
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...


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



  Réponse avec citation
Vieux 29/01/2008, 21h29   #8
Nathan Nobbe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...

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

  Réponse avec citation
Vieux 30/01/2008, 06h22   #9
Chris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...



> 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/
  Réponse avec citation
Vieux 30/01/2008, 13h23   #10
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...


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



  Réponse avec citation
Vieux 31/01/2008, 00h53   #11
Richard Lynch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...

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?
  Réponse avec citation
Vieux 31/01/2008, 13h12   #12
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...


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.

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
  Réponse avec citation
Vieux 31/01/2008, 13h19   #13
Zoltán Németh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...

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
>

  Réponse avec citation
Vieux 31/01/2008, 13h34   #14
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Another question about functions...


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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h19.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,30538 seconds with 22 queries