pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Smith <chris@interspire.com>
To: 'Seader, Cameron' <CSeader@idahopower.com>
To: pgsql-php@postgresql.org
Subject: Re: pg_fetch_row Problem
Date: Tue, 2 Mar 2004 11:17:25 +1100
Message-ID: <003401c3ffeb$c3775140$0d00a8c0@chris> (raw)
In-Reply-To: <71B8A8BEC516CF46835CA629156CF21110383A@bedford.idacorp.local>

Hi Cameron,

I think the reason is you're going beyond the number of results you have
for that query.

Rewrite the while(...) loop to look like this:

$result_count = 0;
while($result_count < $count) {
  $row = pg_fetch_row($result, $result_count);
.........
}

See if that works.

Chris.

-----Original Message-----
From: pgsql-php-owner@postgresql.org
[mailto:pgsql-php-owner@postgresql.org] On Behalf Of Seader, Cameron
Sent: Tuesday, March 02, 2004 10:50 AM
To: pgsql-php@postgresql.org
Subject: [PHP] pg_fetch_row Problem


Greetings,
I am not sure what is going on with my script here, but i am getting
this error when i run it.
Warning: pg_fetch_row(): Unable to jump to row 706 on PostgreSQL result
index 3. in /var/www/html/PMS/csv_export.php on line 32

Warning: Cannot modify header information - headers already sent by
(output started at /var/www/html/PMS/csv_export.php:4) in
/var/www/html/PMS/csv_export.php on line 59

Warning: Cannot modify header information - headers already sent by
(output started at /var/www/html/PMS/csv_export.php:4) in
/var/www/html/PMS/csv_export.php on line 62

Warning: Cannot modify header information - headers already sent by
(output started at /var/www/html/PMS/csv_export.php:4) in
/var/www/html/PMS/csv_export.php on line 63

Warning: Cannot modify header information - headers already sent by
(output started at /var/www/html/PMS/csv_export.php:4) in
/var/www/html/PMS/csv_export.php on line 64 Can anyone tell me what is
going on here??????? I am including my script here below so you can see
what it is doing, maybe you all can see something im not: <?php
pg_connect("host=172.18.74.10 port=5432 dbname=acquisuite_db
user=pgadmin password=pgadmin") 
						or die ( 'Unable to
connect to server.' ); 
						printf("Connected
Successfully");

$MM_param1__panels = ''%'';
if (isset($HTTP_GET_VARS['panel'])) {
  $MM_param1__panels = $HTTP_GET_VARS['panel'];
}
$MM_param2__panels = ''%'';
if (isset($HTTP_GET_VARS['startdate'])) {
  $MM_param2__panels = $HTTP_GET_VARS['startdate'];
}
$MM_param3__panels = ''%'';
if (isset($HTTP_GET_VARS['enddate'])) {
  $MM_param3__panels = $HTTP_GET_VARS['enddate'];
}
$MM_param4__panels = ''%'';
if (isset($HTTP_GET_VARS['order'])) {
  $MM_param4__panels = $HTTP_GET_VARS['order'];
}
						
$query = sprintf("SELECT * FROM %s WHERE utctime AT TIME ZONE 'MST'
BETWEEN '%s' AND '%s' ORDER BY utctime %s",
$MM_param1__panels,$MM_param2__panels,$MM_param3__panels,$MM_param4__pan
els);
						
$result = pg_exec($query);
$count = pg_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= pg_fieldname($result,$i)."\t";
}

while($row = pg_fetch_row($result,$result_count++)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == ""){
      $value = "\t";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might be multi
line. # the good news is that numbers remain numbers in Excel even
though quoted.
      $value = '"' . $value . '"' . "\t";
    }
    $line .= $value;
  }
  $data .= trim($line)."\n";
}
# this line is needed because returns embedded in the data have "\r" #
and this looks like a "box character" in Excel
  $data = str_replace("\r", "", $data);

# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel. if
($data == "") {
  $data = "\nno matching records found\n";
}

# This line will stream the file to the user rather than spray it across
the screen
header("Content-type: application/octet-stream");

# replace excelfile.xls with whatever you want the filename to default
to
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo $header."\n".$data; 
?>

Any Help would be appreciated.
Thanks,

Cameron Seader
mailto:CSeader@Idahopower.com
1.208.388.2582 Office



[INFO] -- Access Manager:
This transmission may contain information that is privileged,
confidential and/or exempt from disclosure under applicable law.  If you
are not the intended recipient, you are hereby notified that any
disclosure, copying, distribution, or use of the information contained
herein (including any reliance thereon) is STRICTLY PROHIBITED. If you
received this transmission in error, please immediately contact the
sender and destroy the material in its entirety, whether in electronic
or hard copy format.  Thank you.   A2



---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if
your
      joining column's datatypes do not match





view thread (7+ messages)  latest in thread

Message-ID: <003401c3ffeb$c3775140$0d00a8c0@chris>
Permalink:  ../003401c3ffeb$c3775140$0d00a8c0@chris/
Also on:    postgresql.org/message-id/003401c3ffeb$c3775140$0d00a8c0@chris

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: chris@interspire.com, CSeader@idahopower.com
  Subject: Re: pg_fetch_row Problem
  In-Reply-To: <003401c3ffeb$c3775140$0d00a8c0@chris>
  References: <71B8A8BEC516CF46835CA629156CF21110383A@bedford.idacorp.local> <003401c3ffeb$c3775140$0d00a8c0@chris>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox