Re: Cancel a query when user leaves a web page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



<body onunload(<?close_connection($connection)?>)>

onunload above can't call function from PHP, but it called from _javascript_, you can create _javascript_ function to call PHP function/file that you wanna PHP do 

<?php
// close_connection.php
include(
'connection.php');
global
$connection;

function close_connection(
$connection){
// close_connection here
// .....
// .....
// .....

}

close_connection(
$connection);
echo
"<SCRIPT>window.close();</SCRIPT>";
?>

---------

<html>

<SCRIPT LANGUAGE="_javascript_">
<!-- Begin
function leave() {
window.open('close_connection.php','','toolbar=no,menubar=no,location=no,height=10,width=10');
}
// End -->
</SCRIPT>

<body onunload = "leave()">

</body>
</html>

----- Original Message -----
From: Noel
Sent: Tuesday, November 18, 2003 10:33 AM
Subject: [PHP] Cancel a query when user leaves a web page

Hi all,

I have a small problem. Is it possible to cancel a running query when a person leave or pressed the stop button in my web page.

I've been thinking about mixing php and _javascript_. Is this the best way to go about it?

basic out line of my code:
<html><head>....stuff....</head>
<body>...stuff
<?php
    $connection = pg_connect(host, dbname, user);

    pg_send_query($connection, "SELECT * FROM blah");

    // collect the results and display etc..
?>
</body></html>
The query can take some time.
And when the page is left the query is still running on postmaster.

Have tried
<?php
    include "functions.php";
    $connection = pg_connect(host, dbname, user);
?>
<html><body onunload(<?close_connection($connection)?>)>
<?php
    echo $connection;
    pg_send_query($connection, "SELECT * FROM blah");

    // collect the results and display etc..
?>
</body></html>

The function, close_connection($connection), is defined in the include file, which is the connection is busy, cancels the query and closes the connection.

This gives the following error:

Resource id #1
Warning: pg_send_query(): 1 is not a valid PostgreSQL link resource in /home/fauxn/public_html/singleAArepeats/test.php on line 11

Any suggestions welcome.

Many thanks
-- 
Noel Faux
Department of Biochemistry and Molecular Biology
Monash University
Clayton 3168
Victoria
Australia

[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux