[PHP-DB] Web Printing

2005-03-31 Thread Ng Hwee Hwee
Hi all,

i am very perplexed now and i hope you guys can help me.

i am reading 50,000 records from mySQL database and i need to print them out in 
a report format. However, i also need to print a page number through PHP on all 
the pages (for example, Page 1 of 200) and display a header and a footer.

i know i can print out a header and footer using HTML thead and tfoot. 
However, the tfoot doesn't always stay at the bottom of the page. For 
example, if the the last page only have 2 records, the tfoot will appear 
pretty high on the page.

i am wondering how can i use PHP to fix the position of my header and footer 
and also display my page numbers and total number of pages to be printed.

all help is very much appreciated 

thank you,
hwee :o)

[suspicious - maybe spam] [PHP-DB] [suspicious - maybe spam] RE: [PHP-DB] Web Printing

2005-03-31 Thread Bastien Koert
Use a pdf format...far more control
see www.fpdf.org
Bastien
From: Ng Hwee Hwee [EMAIL PROTECTED]
To: PHP DB List php-db@lists.php.net
Subject: [PHP-DB] Web Printing
Date: Thu, 31 Mar 2005 18:24:41 +0800
Hi all,
i am very perplexed now and i hope you guys can help me.
i am reading 50,000 records from mySQL database and i need to print them 
out in a report format. However, i also need to print a page number through 
PHP on all the pages (for example, Page 1 of 200) and display a header 
and a footer.

i know i can print out a header and footer using HTML thead and tfoot. 
However, the tfoot doesn't always stay at the bottom of the page. For 
example, if the the last page only have 2 records, the tfoot will appear 
pretty high on the page.

i am wondering how can i use PHP to fix the position of my header and 
footer and also display my page numbers and total number of pages to be 
printed.

all help is very much appreciated
thank you,
hwee :o)
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Why does this code/query hang time out ?

2005-03-31 Thread -{ Rene Brehmer }-
Hi gang
My CPU database (http://metalbunny.net/computers/cpudb.php) - still a work 
in progress - used to be in 1 table, but for several reasons I've decided 
it's better to split the data into multiple related tables. Obviously this 
means I have to rewrite the query tool for it, and that's where my problem 
lies. I've included the code I'm working with below, it's a little 
different than the one for the above URL, as it uses my new faster 
templates and relies more on the database than the old code did.

All the DB connect stuff is in the template, and I use MySQL. The new 
version isn't available online, it's only on my local development server. 
I'm pretty sure it's simply a coding problem, but for the life of me I 
can't find anything that looks wrong ...  but then I've been staring at it 
for hours...

My problem came after I tried making it possible to pick 'all' as a search 
option in make  model, and now, nomatter whether it's set to all or not, 
and nomatter what's in the search field, the code stalls and hangs ... and 
in the last tries, Firefox ended up closing down ...

I tried putting athlon in the search box, and just leave everything on 
default, and the generated query looks like this:

SELECT 
make.makeID,makeName,model.modelID,modelName,fsb2,socket.socketID,socketName,cpuID,variant,clock,multi,fsb,l1,l2,l3,vcore,vcache 
FROM cpu_maker AS make,cpu_model AS model,cpu_socket AS socket,cpu_cpus AS 
cpu WHERE make.makeID=model.makeID AND socket.socketID=model.socketID AND 
cpu.modelID=model.modelID AND model.modelName LIKE '%athlon%' OR `variant` 
LIKE '%athlon%' AND make.makeID0 AND socket.socketID0

Leaving the search box empty produces no result - it's an unintended 
leftover from the old code that I haven't found a good way to get around yet.

The code I'm working on looks like this (beware, it's rather long):
?php
// load dependencies
require('../include/sql.php');
// set data for template
$section = 'tools';
$style2 = 'cputables.css';
$title = 'CPU Database';
$menu = true;
// begin to build query string
$query = 'none';
$basequery = 'SELECT 
make.makeID,makeName,model.modelID,modelName,fsb2,socket.socketID,socketName,cpuID,variant,clock,multi,fsb,l1,l2,l3,vcore,vcache
  FROM cpu_maker AS make,cpu_model AS model,cpu_socket AS 
socket,cpu_cpus AS cpu
  WHERE make.makeID=model.makeID AND 
socket.socketID=model.socketID AND cpu.modelID=model.modelID';

// part 1, search parameters
if (! empty($_GET['search'])) {
  $query = $basequery;
  $setorder = true;
  $query .=  AND model.modelName LIKE '%.$_GET['search'].%';
  $query .=  OR `variant` LIKE '%.$_GET['search'].%';
  if ($_GET['make'] != 'all') {
$query .=  AND make.makeID='.$_GET['make'].';
  } else {
$query .=  AND make.makeID0;
  }
  if ($_GET['socket'] != 'all') {
$query .=  AND socket.socketID='.$_GET['socket'].';
  } else {
$query .=  AND socket.socketID0;
  }
  $linkquery = 
substr($_SERVER['QUERY_STRING'],0,strpos($_SERVER['QUERY_STRING'], 'order'));
}

// part 2, sort order
if ($setorder) {
  switch ($_GET['order']) {
case 'socket':
  $query .= ' ORDER BY `socketName`';
  break;
case 'vcache':
  $query .= ' ORDER BY `vcache`';
  break;
case 'vcore':
  $query .= ' ORDER BY `vcore`';
  break;
case 'l2':
  $query .= ' ORDER BY `l2`';
  break;
case 'l1':
  $query .= ' ORDER BY `l1`';
  break;
case 'fsb':
  $query .= ' ORDER BY `fsb`';
  break;
case 'multi':
  $query .= ' ORDER BY `multi`';
  break;
case 'clock':
  $query .= ' ORDER BY `clock`';
  break;
case 'variant':
  $query .= ' ORDER BY `variant`';
  break;
case 'model':
  $query .= ' ORDER BY `modelName`';
  break;
case 'make':
default:
  $query .= ' ORDER BY `makeName`';
  break;
  }
  // part 2b, asc/desc
  switch ($_GET['ad']) {
case 'd':
  $query .= ' DESC';
  break;
case 'a':
default:
  $query .= ' ASC';
  break;
  }
}
// include template
require('../include/temptop2.php');
if ($query != 'none') {
  $result = mysql_query($query) or die('Unable to do 
querybr'.mysql_error().'brbr'.$query.'br');
  $numrows = mysql_num_rows($result);
  if (! isset($numrows)) {
$numrows = 0;
  }
}
?
p align=left class=txtThis is a beta version of this database. As 
such some minor errors in the operation
can be expected, and all features may not work equally reliable. The 
detailed information for when you click makes or model have not yet been 
made for all CPUs,
but this work is underway. The database is not entirely up to date, or 
complete, but as time permits and information becomes available,
it will be updated with the missing information.br
br
If you find any errors, or would like some additional functionality, plz 
use the a href=../contact.php class=linkcontact form/a to message 
me./p

div align=center
form action=?php echo($_SERVER['PHP_SELF']); ? method=get
table width=560 

Re: [PHP-DB] OCI ignoring NLS_DATE_FORMAT parameter

2005-03-31 Thread Christopher Jones
Doug McMaster wrote:
Regardless of how I set the NLS_DATE_FORMAT parameter, when I do a select 
statement DATE fields are returned in the Oracle default DD-MON-RR format.

I can successfully set NLS_DATE_FORMAT using either an environment variable 
and restarting apache or by using ALTER SESSION SET NLS_DATE_FORMAT = 
'DD-MM- HH24:MI:SS' (I would prefer to use this method).

I can verify that the NLS_DATE_FORMAT is set to my desired format both before 
and after my select statement by running the query SELECT * FROM 
NLS_SESSION_PARAMETERS WHERE PARAMETER='NLS_DATE_FORMAT' in my script.

This problem occurs with both PEAR DB, and with ADODB oci8 drivers.  However 
if I use the ADODB oracle drivers, which use the older ora functions instead 
of the oci functions, ALTER SESSION works and I am able to retrieve dates in 
the format I set.  Unfortunately, the software I'm working on uses PEAR 
DB_DataObject, and the PEAR DB Oracle driver uses the oci calls.

Version info:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
PHP 4.3.4
Apache 1.3.29
Anyone have any ideas or suggestions on why I'm seeing this problem?
Thanks,
Doug
In ADOdb, make sure to set the format before connecting:
  $db = ADONewConnection(oci8);
  //  $db-debug = true;
  // Date format is set before connecting.
  $db-NLS_DATE_FORMAT = '-MM-DD HH24:MI:SS';
  if ([EMAIL PROTECTED]Connect(false, scott, tiger))
error('Connect', $db-ErrorMsg());
In OCI8, see the scipt below.
In PEAR, . . . it's been a while since I used dates in PEAR.
Chris
--
?php
  $conn = OCILogon(scott, tiger);
  if (!$conn) { echo Error connecting; die; }
  query($conn, select * from  nls_session_parameters where 
parameter='NLS_DATE_FORMAT');
  query($conn, select sysdate from dual);
  alterdate($conn);
  query($conn, select * from  nls_session_parameters where 
parameter='NLS_DATE_FORMAT');
  query($conn, select sysdate from dual);
  exit;
  function query($conn, $query)
  {
$stid = OCIParse($conn, $query);
if (!$stid) { echo Error parsing; die; }
$r = OCIExecute($stid, OCI_DEFAULT);
if (!$r) { echo Error executing; die; }
print 'table border=1';
while ($succ = OCIFetchInto($stid, $row, OCI_RETURN_NULLS)) {
  print 'tr';
  foreach ($row as $item) {
print 'td'.($item?htmlentities($item):'nbsp;').'/td';
  }
  print '/tr';
}
print '/table';
  }
  function alterdate($conn)
  {
$cmd = alter session set nls_date_format = '-MON-DD HH:MI';
$stid = OCIParse($conn, $cmd);
if (!$stid) { echo Error parsing; die; }
$r = ociexecute($stid, OCI_DEFAULT);
if (!$r) { echo Error executing; die; }
  }
?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] ocilogon timeout

2005-03-31 Thread Christopher Jones
Juffermans, Jos wrote:
Hi,
Some of our scripts that generate customer-facing pages, need a connection 
to a database. The problems is that the database is in Norway and - 
allthough we have a VPN setup - the connection isn't always available.

In case the connection cannot be made, we can redirect the customer to a 
nice error page and ask them to try again later. That's not too hard.

The issue is that it takes really really long before ocilogon returns if the
connection cannot be established. Is it possible to set a timeout on 
ocilogon (like you can with eg fsockopen)?

Rgds,
Jos 

Look at the Oracle Net configuration and see if any parameters can
be tweaked.
For example, with Oracle 10.1, editing the client-side sqlnet.ora
file and changing
  NAMES.DIRECTORY_PATH= (TNSNAMES,EZCONNECT)
to
  NAMES.DIRECTORY_PATH= (TNSNAMES)
removes an extra delay when the connection fails.  In this example you
lose the ability to use 10g Easy Connection syntax, which may not
be important to you.
Chris
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Re: Subject: Web Printing

2005-03-31 Thread Ng Hwee Hwee
hi all,

thanx for all your suggestions. however, the css below doesn't seem to help
me solve my tfoot problem. if my tbody is pretty short, the tfoot will
still NOT appear at the bottom of my page but it appears where my tbody
ends (which sometimes ends in the middle of my page). what else can i do??

by the way, i cannot use PDFs to generate my reports as suggested by many of
you kind souls. This is because my clients just want to click on the Print
Monthly Report button and i am suppose to fetch the relevant data from
MySQL DB and print out the report.. they don't need to save them in Excel or
PDF. It is restricted to printing off the IE browser.

The problem that gives me the most headache is how can I know the total
number of pages and the current page number, by using PHP?? I really need
this because a report can be hundreds of pages so page number is very
important to my clients.

Please kindly help me! thank you s much!

Hwee

- Original Message - 
From: Neil Smith [MVP, Digital media] [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, March 31, 2005 9:15 PM
Subject: Subject: Web Printing


 At 10:27 31/03/2005 +, you wrote:
 Message-ID: [EMAIL PROTECTED]
 From: Ng Hwee Hwee [EMAIL PROTECTED]
 To: PHP DB List php-db@lists.php.net
 Date: Thu, 31 Mar 2005 18:24:41 +0800
 Subject: Web Printing
 
 Hi all,
 
 i know i can print out a header and footer using HTML thead and
tfoot.
 However, the tfoot doesn't always stay at the bottom of the page. For
 example, if the the last page only have 2 records, the tfoot will
appear
 pretty high on the page.
 
 i am wondering how can i use PHP to fix the position of my header and
footer

 PHP cannot help you here, it's the wrong tool for the job (it's a hammer
 not a screwdriver so to speak).
 You need to (*must* !!!) use CSS to position and specify the height and
 dimensions of the thead and tfoot thus :


 thead {
  display: table-header-group;
  position: absolute;
  top: 0;
  height: 36pt;
  width: 100%;
 }

 tfoot {
  display: table-footer-group;
  position: absolute;
  bottom: 0;
  height: 36pt;
  width: 100%;
 }

 These should apply *reasonably* well to position your thead and tfoot row
 groups in the same place on each printed page (adjust as desired). You
 *cannot* use PHP to guess the height of the page areas reliably unless
 you are using a fixed pitch font such as a dot matrix line printer. And
 even then it's somewhat guesswork (I've done both).

 But if we're assuming that you're users have laser printers you *must* use
 CSS to do the print layout, PHP line height guessing will not work for
you.

 Cheers - Neil

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



Re: [PHP-DB] Re: Subject: Web Printing

2005-03-31 Thread Mark Cain
Let me encourage you to be open minded about the use of dynamic PDF
generation.  Don't think PDF as in storage and downloading -- think PDF in
the realm of format control.

google class.ezpdf.php

or just use this link:

http://www.google.com/search?hl=enq=class.ezpdf.phpspell=1

Mark Cain


- Original Message -
From: Ng Hwee Hwee [EMAIL PROTECTED]
To: PHP DB List php-db@lists.php.net
Sent: Thursday, March 31, 2005 9:39 PM
Subject: [PHP-DB] Re: Subject: Web Printing


 hi all,

 thanx for all your suggestions. however, the css below doesn't seem to
help
 me solve my tfoot problem. if my tbody is pretty short, the tfoot
will
 still NOT appear at the bottom of my page but it appears where my tbody
 ends (which sometimes ends in the middle of my page). what else can i do??

 by the way, i cannot use PDFs to generate my reports as suggested by many
of
 you kind souls. This is because my clients just want to click on the
Print
 Monthly Report button and i am suppose to fetch the relevant data from
 MySQL DB and print out the report.. they don't need to save them in Excel
or
 PDF. It is restricted to printing off the IE browser.

 The problem that gives me the most headache is how can I know the total
 number of pages and the current page number, by using PHP?? I really need
 this because a report can be hundreds of pages so page number is very
 important to my clients.

 Please kindly help me! thank you s much!

 Hwee

 - Original Message -
 From: Neil Smith [MVP, Digital media] [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Thursday, March 31, 2005 9:15 PM
 Subject: Subject: Web Printing


  At 10:27 31/03/2005 +, you wrote:
  Message-ID: [EMAIL PROTECTED]
  From: Ng Hwee Hwee [EMAIL PROTECTED]
  To: PHP DB List php-db@lists.php.net
  Date: Thu, 31 Mar 2005 18:24:41 +0800
  Subject: Web Printing
  
  Hi all,
  
  i know i can print out a header and footer using HTML thead and
 tfoot.
  However, the tfoot doesn't always stay at the bottom of the page. For
  example, if the the last page only have 2 records, the tfoot will
 appear
  pretty high on the page.
  
  i am wondering how can i use PHP to fix the position of my header and
 footer
 
  PHP cannot help you here, it's the wrong tool for the job (it's a
hammer
  not a screwdriver so to speak).
  You need to (*must* !!!) use CSS to position and specify the height and
  dimensions of the thead and tfoot thus :
 
 
  thead {
   display: table-header-group;
   position: absolute;
   top: 0;
   height: 36pt;
   width: 100%;
  }
 
  tfoot {
   display: table-footer-group;
   position: absolute;
   bottom: 0;
   height: 36pt;
   width: 100%;
  }
 
  These should apply *reasonably* well to position your thead and tfoot
row
  groups in the same place on each printed page (adjust as desired). You
  *cannot* use PHP to guess the height of the page areas reliably unless
  you are using a fixed pitch font such as a dot matrix line printer. And
  even then it's somewhat guesswork (I've done both).
 
  But if we're assuming that you're users have laser printers you *must*
use
  CSS to do the print layout, PHP line height guessing will not work for
 you.
 
  Cheers - Neil

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



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



[suspicious - maybe spam] [PHP-DB] [suspicious - maybe spam] PostgreSQL Backup Script

2005-03-31 Thread Vishal Kashyap @ [SaiHertz]
Dear all,

I am stuck with database backup.
While using pg_dump the utility asks for password but since I require
this process to be automated the password prompt is giving me
headaches
is their any way by which can pass the password automatically.
Like setting up a variable in php  which passes the password to the
pg_dump utility on prompt this way the whole process of pg_dump would
get automated.
One obvious solution was to use .pgpass but it does not appeal me as
it is again a security threat.
any pointers or help may lead to unlocked secret.
--
With Best Regards,
Vishal Kashyap.
Lead Software Developer,
http://saihertz.com,
http://vishalkashyap.tk


  ReplyForward

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



Re: [PHP-DB] Re: Subject: Web Printing

2005-03-31 Thread Ng Hwee Hwee
hi!

thanks for the suggestion.. actually i have tried PDF generation before and
because my clients are japanese companies, the japanese characters don't get
generated correctly.. i am still working on that but it doesn't seem that
easy for me.

furthermore, i really still can't see how PDF allows me to get my page
number and total number of pages intermingled with my main contents. =(

please advise.. thanks s much!

hwee

- Original Message - 
From: Mark Cain [EMAIL PROTECTED]
To: Ng Hwee Hwee [EMAIL PROTECTED]; PHP DB List php-db@lists.php.net
Sent: Friday, April 01, 2005 12:07 PM
Subject: Re: [PHP-DB] Re: Subject: Web Printing


 Let me encourage you to be open minded about the use of dynamic PDF
 generation.  Don't think PDF as in storage and downloading -- think PDF in
 the realm of format control.

 google class.ezpdf.php

 or just use this link:

 http://www.google.com/search?hl=enq=class.ezpdf.phpspell=1

 Mark Cain

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



RE: [PHP-DB] Why does this code/query hang time out ?

2005-03-31 Thread Juffermans, Jos
i Rene,

So far, I have found a few mistakes in your SQL:

$query .=  OR `variant` LIKE '%.$_GET['search'].%';
Why do you have backtick-quotes around variant? Know that backticks are used
to call system commands. You also use these backticks in the ORDER BY lines.
My guess is the backticks are causing your problems.

$query .=  AND make.makeID='.$_GET['make'].';
...
$query .=  AND make.makeID0;
If make.makeID is a number field, why is the value in quotes for the cases
where $_GET['make'] is set? Same with socket.socketID a few lines down.


Unrelated but very important, putting form variables (either GET or POST)
directly into a query is dangerous. If I create a copy of your form and fill
$_GET['search'] with eg:  a%';DELETE * FROM model;SELECT * FROM model WHERE
something LIKE '%a

Your query will be like this: SELECT .. FROM  WHERE  AND
model.modelName LIKE '%a%';DELETE * FROM model;SELECT * FROM model WHERE
something LIKE '%a OR VARIANT 

You can't trust incoming variables.

Jos

-Original Message-
From: -{ Rene Brehmer }- [mailto:[EMAIL PROTECTED]
Sent: 31 March 2005 23:43
To: php-db@lists.php.net
Subject: [PHP-DB] Why does this code/query hang  time out ?


Hi gang

My CPU database (http://metalbunny.net/computers/cpudb.php) - still a work 
in progress - used to be in 1 table, but for several reasons I've decided 
it's better to split the data into multiple related tables. Obviously this 
means I have to rewrite the query tool for it, and that's where my problem 
lies. I've included the code I'm working with below, it's a little 
different than the one for the above URL, as it uses my new faster 
templates and relies more on the database than the old code did.

All the DB connect stuff is in the template, and I use MySQL. The new 
version isn't available online, it's only on my local development server. 
I'm pretty sure it's simply a coding problem, but for the life of me I 
can't find anything that looks wrong ...  but then I've been staring at it 
for hours...

My problem came after I tried making it possible to pick 'all' as a search 
option in make  model, and now, nomatter whether it's set to all or not, 
and nomatter what's in the search field, the code stalls and hangs ... and 
in the last tries, Firefox ended up closing down ...

I tried putting athlon in the search box, and just leave everything on 
default, and the generated query looks like this:

SELECT 
make.makeID,makeName,model.modelID,modelName,fsb2,socket.socketID,socketName
,cpuID,variant,clock,multi,fsb,l1,l2,l3,vcore,vcache 
FROM cpu_maker AS make,cpu_model AS model,cpu_socket AS socket,cpu_cpus AS 
cpu WHERE make.makeID=model.makeID AND socket.socketID=model.socketID AND 
cpu.modelID=model.modelID AND model.modelName LIKE '%athlon%' OR `variant` 
LIKE '%athlon%' AND make.makeID0 AND socket.socketID0

Leaving the search box empty produces no result - it's an unintended 
leftover from the old code that I haven't found a good way to get around
yet.

The code I'm working on looks like this (beware, it's rather long):

?php
// load dependencies
require('../include/sql.php');

// set data for template
$section = 'tools';
$style2 = 'cputables.css';
$title = 'CPU Database';
$menu = true;

// begin to build query string
$query = 'none';
$basequery = 'SELECT 
make.makeID,makeName,model.modelID,modelName,fsb2,socket.socketID,socketName
,cpuID,variant,clock,multi,fsb,l1,l2,l3,vcore,vcache
   FROM cpu_maker AS make,cpu_model AS model,cpu_socket AS 
socket,cpu_cpus AS cpu
   WHERE make.makeID=model.makeID AND 
socket.socketID=model.socketID AND cpu.modelID=model.modelID';

// part 1, search parameters
if (! empty($_GET['search'])) {
   $query = $basequery;
   $setorder = true;

   $query .=  AND model.modelName LIKE '%.$_GET['search'].%';
   $query .=  OR `variant` LIKE '%.$_GET['search'].%';

   if ($_GET['make'] != 'all') {
 $query .=  AND make.makeID='.$_GET['make'].';
   } else {
 $query .=  AND make.makeID0;
   }

   if ($_GET['socket'] != 'all') {
 $query .=  AND socket.socketID='.$_GET['socket'].';
   } else {
 $query .=  AND socket.socketID0;
   }

   $linkquery = 
substr($_SERVER['QUERY_STRING'],0,strpos($_SERVER['QUERY_STRING'],
'order'));
}

// part 2, sort order
if ($setorder) {
   switch ($_GET['order']) {
 case 'socket':
   $query .= ' ORDER BY `socketName`';
   break;
 case 'vcache':
   $query .= ' ORDER BY `vcache`';
   break;
 case 'vcore':
   $query .= ' ORDER BY `vcore`';
   break;
 case 'l2':
   $query .= ' ORDER BY `l2`';
   break;
 case 'l1':
   $query .= ' ORDER BY `l1`';
   break;
 case 'fsb':
   $query .= ' ORDER BY `fsb`';
   break;
 case 'multi':
   $query .= ' ORDER BY `multi`';
   break;
 case 'clock':
   $query .= ' ORDER BY `clock`';
   break;
 case 'variant':
   $query .= ' ORDER BY `variant`';
   break;