Subject Re: [firebird-php] Reformatted
Author masotti
Hi,
seems like you think to program in Delphi Win32 and not in a Web
development model.
Every time you post the page (Button1Click isn't a JS method) you
restart execution of php from the beginning, so your query is reexecuted
again and again.

Let me suggest some hints, see details in code


> `<?php
> require_once("vcl/vcl.inc.php");
> use_unit("forms.inc.php");
> use_unit("extctrls.inc.php");
> use_unit("stdctrls.inc.php");
> $conn = ibase_connect("JAYS-PC:C:/DWebsite/files/APPLY.FDB", "SYSDBA",
> "masterkey");
>
Use ibase_pconnect(), because if you've already a connection opened that
is used; normal connection are closed at the end of script, but it takes
time to reconnect each time. Using pooled connection may speed execution
and simplify program logic.

$stmtf = "SELECT * FOR 1 SKIP ? FROM APPLIED";

Use a form loaded Javascript event to sprintf() and open query: that is
the best moment to do that tipe of management, see below.
>
> //Class definition
> class QuerySample extends Page
> {
> public $displabel = null;
> public $Button1 = null;
> public $Enterrec = null;
> public $datalabel = null;
> public $labelinput = null;
>
>
>
> function Button1Click($sender, $params)
>
> {
> GLOBAL $conn;
> GLOBAL $iaquery;
> GLOBAL $row;
> GLOBAL $stmt;
> GLOBAL $rcursor;
>
> // if input record number was N for Next,
> // cant get N or next to work
> // i must have to pass varible to session, I thought being global
> $rcursor would retain value.??
>
No, as explained elsewhrere D4PHP destroys $_SESSION in page loading.
For workaround see:
http://www.qadram.com/vcl4php/forums/viewtopic.php?t=480
The simplest solution is to use a hidden field in the form. You can
retrieve in PHP with

$val = $this->HiddenField1->value;

and with JavaScript with

aa = findObj('HiddenField1').value;

> ... skipped
> }
>
function QuerySampleJSLoaded {

// As explained D4PHP erases $_SESSION vars each time a page is loaded. But here we can do all in JSLoaded().
// Beware: PHP code is executed BEFORE dumping page code to client,
// Javascript code is executed AFTER the HTML has been loaded to client

global $rcursor, $conn, $stmtf ;
$job_id = "<b>EOF</b>";
if ( $rsrc = ibase_query ( $conn, $stmtf, $rcursor )) {
if ( $row = ibase_fetch_object ( $rsrc, IBASE_TEXT )) {
$job_id = $row->JOB_ID;
}
}
echo "var aa = \"$job_id\";
";
?>
// here is javascript executed AFTER page loaded (code expanded for clarity, so you can debug it)
var xx = findObj('displabel');
xx.innerHTML = aa;
<?php
}

> }
>
> global $application;
>
> global $QuerySample;
>
> //Creates the form
> $QuerySample = new QuerySample($application);
>
> //Read from resource file
> $QuerySample->loadResource(__FILE__);
>
> //Shows the form
> $QuerySample->show();
>
> ?>
>
Hope this helps (and not being too much off topic in this list).
Ciao.
Mimmo.