CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> CodeCharge.Discussion

 Session variables?

Print topic Send  topic

Author Message
Glenn Holden
Posted: 03/15/2002, 7:03 PM

Are session variables automatically 'passed'?

Are they available in all pages after they are created, until unregistered
or the session is closed?

If No, how do I pass a session variable that I am creating in an after
insert event?

Geert Larsen
Posted: 03/16/2002, 3:06 AM

Sure!
check this:
the stateless web: http://coveryourasp.com/Session.asp

/geert

"Glenn Holden" <glenn@nilenet.com> wrote in message
news:a6uclq$fnu$1@news.codecharge.com...
> Are session variables automatically 'passed'?
>
> Are they available in all pages after they are created, until unregistered
> or the session is closed?
>
> If No, how do I pass a session variable that I am creating in an after
> insert event?
>
>

Glenn Holden
Posted: 03/16/2002, 8:02 AM

A helpful article, Geert, thank you.
I am however doing this with PHP/MySQL. I assume the concepts are all the
same so let me explain my problem.


In a CC After Insert event I have:

set_session("OrderRN",$db->query("select last_insert_id()"));

but when I use that variable in the next page to filter a grid, it returns
0 records.
Any ideas?

Thanks
Glenn




"Geert Larsen" <gl@fritzhansen.com> wrote in message
news:a6v8v2$23l$1@news.codecharge.com...
> Sure!
> check this:
> the stateless web: http://coveryourasp.com/Session.asp
>
> /geert
>
> "Glenn Holden" <glenn@nilenet.com> wrote in message
>news:a6uclq$fnu$1@news.codecharge.com...
> > Are session variables automatically 'passed'?
> >
> > Are they available in all pages after they are created, until
unregistered
> > or the session is closed?
> >
> > If No, how do I pass a session variable that I am creating in an after
> > insert event?
> >
> >
>
>

guest
Posted: 03/16/2002, 9:42 AM

Here what I do:

Extend the DB_Sql object using this file (new_db.inc.php):

<?php
class New_DB_Sql extends DB_Sql {

var $Last_ID = 0;


/* returns Last_ID */
function last_id(){
return $this->Last_ID;
}

/* public: modefied: perform a query */
function query($Query_String) {
/* No empty queries, please, since PHP4 chokes on them. */
if ($Query_String == "")
/* The empty query string is passed on from the constructor,
* when calling the class without a query, e.g. in situations
* like these: '$db = new DB_Sql_Subclass;'
*/
return 0;

if (!$this->connect()) {
return 0; /* we already complained in connect() about that. */
};

# New query, discard previous result.
if ($this->Query_ID) {
$this->free();
}

if ($this->Debug)
printf("Debug: query = %s<br>\n", $Query_String);

$this->Query_ID = @mysql_query($Query_String,$this->Link_ID);
/*I just added this line below */
$this->Last_ID = mysql_insert_id ($this->Link_ID);
$this->Row = 0;
$this->Errno = mysql_errno();
$this->Error = mysql_error();
if (!$this->Query_ID) {
$this->halt("Invalid SQL: ".$Query_String);
}

# Will return nada if it fails. That's fine.
return $this->Query_ID;
}
}
?>

Then in CC->Modules->Common I obtain generated code and change this:

$db = new DB_Sql();

to this:

include("./new_db.inc.php");
$db = new New_DB_Sql();


Then whenever you want the last insert id you can reference it with
this function:

$db->last_id();

Or in your case:

set_session('OrderRN',$db->last_id());

And after I've typed all this, I got to thinking that when you
reference it in a function you need to reference the variable like
this:

Global $OrderRN;

before you can reference it. :) Funny thing is, add that to yours
and yours will probably work. :) I extend the DB_Sql object just
because I like to stay as modular as possible.

Basil

On Sat, 16 Mar 2002 09:02:04 -0700, "Glenn Holden" <glenn@nilenet.com>
wrote:

>A helpful article, Geert, thank you.
>I am however doing this with PHP/MySQL. I assume the concepts are all the
>same so let me explain my problem.
>
>
>In a CC After Insert event I have:
>
>set_session("OrderRN",$db->query("select last_insert_id()"));
>
>but when I use that variable in the next page to filter a grid, it returns
>0 records.
>Any ideas?
>
>Thanks
>Glenn
>
>
>
>
>"Geert Larsen" <gl@fritzhansen.com> wrote in message
>news:a6v8v2$23l$1@news.codecharge.com...
>> Sure!
>> check this:
>> the stateless web: http://coveryourasp.com/Session.asp
>>
>> /geert
>>
>> "Glenn Holden" <glenn@nilenet.com> wrote in message
>>news:a6uclq$fnu$1@news.codecharge.com...
>> > Are session variables automatically 'passed'?
>> >
>> > Are they available in all pages after they are created, until
>unregistered
>> > or the session is closed?
>> >
>> > If No, how do I pass a session variable that I am creating in an after
>> > insert event?
>> >
>> >
>>
>>
>
>
Glenn Holden
Posted: 03/16/2002, 2:27 PM

Thanks Basil,

1. I guess I don't understand why what I tried didn't work. I also tried
this:

$orn = $db->query("select last_insert_id()");
set_session("OrderRN",$orn);

(and it didn't work either)

2. Why and where would I make the $OrderRN global? I tried it in the page
load event and the common module and neither worked.

3. I still don't have a grasp on variable scope with PHP and HTML. How
global is global?

Thanks again for the help.
Glenn



<baze22N_O_SPAM@yahoo.com> wrote in message
news:3c93805e.106080866@news.codecharge.com...
> Here what I do:
>
> Extend the DB_Sql object using this file (new_db.inc.php):
>
> <?php
> class New_DB_Sql extends DB_Sql {
>
> var $Last_ID = 0;
>
>
> /* returns Last_ID */
> function last_id(){
> return $this->Last_ID;
> }
>
> /* public: modefied: perform a query */
> function query($Query_String) {
> /* No empty queries, please, since PHP4 chokes on them. */
> if ($Query_String == "")
> /* The empty query string is passed on from the constructor,
> * when calling the class without a query, e.g. in situations
> * like these: '$db = new DB_Sql_Subclass;'
> */
> return 0;
>
> if (!$this->connect()) {
> return 0; /* we already complained in connect() about that. */
> };
>
> # New query, discard previous result.
> if ($this->Query_ID) {
> $this->free();
> }
>
> if ($this->Debug)
> printf("Debug: query = %s<br>\n", $Query_String);
>
> $this->Query_ID = @mysql_query($Query_String,$this->Link_ID);
> /*I just added this line below */
> $this->Last_ID = mysql_insert_id ($this->Link_ID);
> $this->Row = 0;
> $this->Errno = mysql_errno();
> $this->Error = mysql_error();
> if (!$this->Query_ID) {
> $this->halt("Invalid SQL: ".$Query_String);
> }
>
> # Will return nada if it fails. That's fine.
> return $this->Query_ID;
> }
> }
> ?>
>
> Then in CC->Modules->Common I obtain generated code and change this:
>
> $db = new DB_Sql();
>
> to this:
>
> include("./new_db.inc.php");
> $db = new New_DB_Sql();
>
>
> Then whenever you want the last insert id you can reference it with
> this function:
>
> $db->last_id();
>
> Or in your case:
>
> set_session('OrderRN',$db->last_id());
>
> And after I've typed all this, I got to thinking that when you
> reference it in a function you need to reference the variable like
> this:
>
> Global $OrderRN;
>
> before you can reference it. :) Funny thing is, add that to yours
> and yours will probably work. :) I extend the DB_Sql object just
> because I like to stay as modular as possible.
>
> Basil
>
> On Sat, 16 Mar 2002 09:02:04 -0700, "Glenn Holden" <glenn@nilenet.com>
> wrote:
>
> >A helpful article, Geert, thank you.
> >I am however doing this with PHP/MySQL. I assume the concepts are all
the
> >same so let me explain my problem.
> >
> >
> >In a CC After Insert event I have:
> >
> >set_session("OrderRN",$db->query("select last_insert_id()"));
> >
> >but when I use that variable in the next page to filter a grid, it
returns
> >0 records.
> >Any ideas?
> >
> >Thanks
> >Glenn
> >
> >
> >
> >
> >"Geert Larsen" <gl@fritzhansen.com> wrote in message
> >news:a6v8v2$23l$1@news.codecharge.com...
> >> Sure!
> >> check this:
> >> the stateless web: http://coveryourasp.com/Session.asp
> >>
> >> /geert
> >>
> >> "Glenn Holden" <glenn@nilenet.com> wrote in message
> >>news:a6uclq$fnu$1@news.codecharge.com...
> >> > Are session variables automatically 'passed'?
> >> >
> >> > Are they available in all pages after they are created, until
> >unregistered
> >> > or the session is closed?
> >> >
> >> > If No, how do I pass a session variable that I am creating in an
after
> >> > insert event?
> >> >
> >> >
> >>
> >>
> >
> >
>

Glenn Holden
Posted: 03/16/2002, 2:44 PM

BTW:

Here's the stock code for the set_session function. It does declare the
param-name global...

function set_session($param_name, $param_value)
{
global ${$param_name};
if(session_is_registered($param_name))
session_unregister($param_name);
${$param_name} = $param_value;
session_register($param_name);
}





<baze22N_O_SPAM@yahoo.com> wrote in message
news:3c93805e.106080866@news.codecharge.com...
> Here what I do:
>
> Extend the DB_Sql object using this file (new_db.inc.php):
>
> <?php
> class New_DB_Sql extends DB_Sql {
>
> var $Last_ID = 0;
>
>
> /* returns Last_ID */
> function last_id(){
> return $this->Last_ID;
> }
>
> /* public: modefied: perform a query */
> function query($Query_String) {
> /* No empty queries, please, since PHP4 chokes on them. */
> if ($Query_String == "")
> /* The empty query string is passed on from the constructor,
> * when calling the class without a query, e.g. in situations
> * like these: '$db = new DB_Sql_Subclass;'
> */
> return 0;
>
> if (!$this->connect()) {
> return 0; /* we already complained in connect() about that. */
> };
>
> # New query, discard previous result.
> if ($this->Query_ID) {
> $this->free();
> }
>
> if ($this->Debug)
> printf("Debug: query = %s<br>\n", $Query_String);
>
> $this->Query_ID = @mysql_query($Query_String,$this->Link_ID);
> /*I just added this line below */
> $this->Last_ID = mysql_insert_id ($this->Link_ID);
> $this->Row = 0;
> $this->Errno = mysql_errno();
> $this->Error = mysql_error();
> if (!$this->Query_ID) {
> $this->halt("Invalid SQL: ".$Query_String);
> }
>
> # Will return nada if it fails. That's fine.
> return $this->Query_ID;
> }
> }
> ?>
>
> Then in CC->Modules->Common I obtain generated code and change this:
>
> $db = new DB_Sql();
>
> to this:
>
> include("./new_db.inc.php");
> $db = new New_DB_Sql();
>
>
> Then whenever you want the last insert id you can reference it with
> this function:
>
> $db->last_id();
>
> Or in your case:
>
> set_session('OrderRN',$db->last_id());
>
> And after I've typed all this, I got to thinking that when you
> reference it in a function you need to reference the variable like
> this:
>
> Global $OrderRN;
>
> before you can reference it. :) Funny thing is, add that to yours
> and yours will probably work. :) I extend the DB_Sql object just
> because I like to stay as modular as possible.
>
> Basil
>
> On Sat, 16 Mar 2002 09:02:04 -0700, "Glenn Holden" <glenn@nilenet.com>
> wrote:
>
> >A helpful article, Geert, thank you.
> >I am however doing this with PHP/MySQL. I assume the concepts are all
the
> >same so let me explain my problem.
> >
> >
> >In a CC After Insert event I have:
> >
> >set_session("OrderRN",$db->query("select last_insert_id()"));
> >
> >but when I use that variable in the next page to filter a grid, it
returns
> >0 records.
> >Any ideas?
> >
> >Thanks
> >Glenn
> >
> >
> >
> >
> >"Geert Larsen" <gl@fritzhansen.com> wrote in message
> >news:a6v8v2$23l$1@news.codecharge.com...
> >> Sure!
> >> check this:
> >> the stateless web: http://coveryourasp.com/Session.asp
> >>
> >> /geert
> >>
> >> "Glenn Holden" <glenn@nilenet.com> wrote in message
> >>news:a6uclq$fnu$1@news.codecharge.com...
> >> > Are session variables automatically 'passed'?
> >> >
> >> > Are they available in all pages after they are created, until
> >unregistered
> >> > or the session is closed?
> >> >
> >> > If No, how do I pass a session variable that I am creating in an
after
> >> > insert event?
> >> >
> >> >
> >>
> >>
> >
> >
>

Glenn Holden
Posted: 03/16/2002, 4:05 PM

I found my problem here...

> set_session("OrderRN",$db->query("select last_insert_id()"));


Wasn't setting the session variable correctly since the last_insert_id
wasn't being retreived properly. I wanted a single value returned so when I
switched to CC's get_db_value($sql) function and used it like:

set_session("OrderRN",get_db_value("select last_insert_id()"));

it works!!!

I love learning (*%#%*) !
Glenn


"Glenn Holden" <glenn@nilenet.com> wrote in message
news:a6vq9o$1ji$1@news.codecharge.com...
> A helpful article, Geert, thank you.
> I am however doing this with PHP/MySQL. I assume the concepts are all the
> same so let me explain my problem.
>
>
> In a CC After Insert event I have:
>
> set_session("OrderRN",$db->query("select last_insert_id()"));
>
> but when I use that variable in the next page to filter a grid, it
returns
> 0 records.
> Any ideas?
>
> Thanks
> Glenn
>
>
>
>
> "Geert Larsen" <gl@fritzhansen.com> wrote in message
>news:a6v8v2$23l$1@news.codecharge.com...
> > Sure!
> > check this:
> > the stateless web: http://coveryourasp.com/Session.asp
> >
> > /geert
> >
> > "Glenn Holden" <glenn@nilenet.com> wrote in message
> >news:a6uclq$fnu$1@news.codecharge.com...
> > > Are session variables automatically 'passed'?
> > >
> > > Are they available in all pages after they are created, until
> unregistered
> > > or the session is closed?
> > >
> > > If No, how do I pass a session variable that I am creating in an after
> > > insert event?
> > >
> > >
> >
> >
>
>

guest
Posted: 03/17/2002, 5:20 AM

>2. Why and where would I make the $OrderRN global? I tried it in the page
>load event and the common module and neither worked.
>
>3. I still don't have a grasp on variable scope with PHP and HTML. How
>global is global?
>

PHP's scope on global variables is similar to other languages, but
with a twist. A global variable (and when you set a session variable,
its scope is considered global) it is available throughout your
program *but* in a function you have to tell the function it is global
otherwise the function assumes it is local.

Take this code for example:

<?php

$aglobalvar = "Hello World";

function a(){
print "function a: " . $aglobalvar . "<br>\n";
}

function b(){
global $aglobalvar;
print "function b: " . $aglobalvar . "<br>\n";
}

function c(){
print "function c: " . $GLOBALS['aglobalvar'] . "<br>\n";
}

a();
b();
c();

?>

In most languages I've used, I would expect all three to print out the
Hello World message. But in PHP only b & c prin it out.

After I typed in that last message I was thinking you might have been
trying to use a global variable like in my function a() example.

Glad you got your code working.

Basil
Glenn Holden
Posted: 03/17/2002, 8:45 AM

Most helpful. Thank you Basil.

Glenn


<baze22N_O_SPAM@yahoo.com> wrote in message
news:3c94947b.176765695@news.codecharge.com...
> >2. Why and where would I make the $OrderRN global? I tried it in the
page
> >load event and the common module and neither worked.
> >
> >3. I still don't have a grasp on variable scope with PHP and HTML. How
> >global is global?
> >
>
> PHP's scope on global variables is similar to other languages, but
> with a twist. A global variable (and when you set a session variable,
> its scope is considered global) it is available throughout your
> program *but* in a function you have to tell the function it is global
> otherwise the function assumes it is local.
>
> Take this code for example:
>
> <?php
>
> $aglobalvar = "Hello World";
>
> function a(){
> print "function a: " . $aglobalvar . "<br>\n";
> }
>
> function b(){
> global $aglobalvar;
> print "function b: " . $aglobalvar . "<br>\n";
> }
>
> function c(){
> print "function c: " . $GLOBALS['aglobalvar'] . "<br>\n";
> }
>
> a();
> b();
> c();
>
> ?>
>
> In most languages I've used, I would expect all three to print out the
> Hello World message. But in PHP only b & c prin it out.
>
> After I typed in that last message I was thinking you might have been
> trying to use a global variable like in my function a() example.
>
> Glad you got your code working.
>
> Basil


   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.