problem execution order

Hello to everyone...
I'm having a little problem with displaying a number of products in my
shoping cart that I'm writing from scratch.
The structure of a site is following: INDEX.php is my main page where
everything else loads up. So, my shop component comes as
index.php?kom=shop and a little switch($kom) in at the begining of
index.php switches the main content. That content, in this case shop
component, loads into <div id='mainContent'>include ('$content')</div>.

Every activity of shop component runs by sending task variable through
URL to itself where another SWITCH is. So, to add something to cart I
do index.php?kom=shop&task=add and it's added. It gets
$_POST['prod_id'] and component does function that runs SQL query
according to task=add.
I also have a little "module", in index.php, that says: "Number of
prod. in cart is :14". It is put directly into index.php so that it
could be seen no mater which component is loaded. Because of design of
a page this module is situated before the content of components that
are loaded.
My problem is that this module runs it's SQL query and gets number of
products in cart before the component shop runs insert function. So in
komponent shop I will have real situation from database but in my
module I'll have number of products that is not up-to date. I have
to refresh page so that cart module runs it's query again and gets real
numbers...
Do you have any idea how to get my cart module run after insert has
been done yet presented in HTML before shop component
luigi7up [ Mi, 17 Januar 2007 21:23 ] [ ID #1598909 ]

Re: problem execution order

luigi7up wrote:
> Hello to everyone...
> I'm having a little problem with displaying a number of products in my
> shoping cart that I'm writing from scratch.
> The structure of a site is following: INDEX.php is my main page where
> everything else loads up. So, my shop component comes as
> index.php?kom=shop and a little switch($kom) in at the begining of
> index.php switches the main content. That content, in this case shop
> component, loads into <div id='mainContent'>include ('$content')</div>.
>
> Every activity of shop component runs by sending task variable through
> URL to itself where another SWITCH is. So, to add something to cart I
> do index.php?kom=shop&task=add and it's added. It gets
> $_POST['prod_id'] and component does function that runs SQL query
> according to task=add.
> I also have a little "module", in index.php, that says: "Number of
> prod. in cart is :14". It is put directly into index.php so that it
> could be seen no mater which component is loaded. Because of design of
> a page this module is situated before the content of components that
> are loaded.
> My problem is that this module runs it's SQL query and gets number of
> products in cart before the component shop runs insert function. So in
> komponent shop I will have real situation from database but in my
> module I'll have number of products that is not up-to date. I have
> to refresh page so that cart module runs it's query again and gets real
> numbers...
> Do you have any idea how to get my cart module run after insert has
> been done yet presented in HTML before shop component
>

As you already use div-tags, you can make the output from your module to use
one too and in your CSS file you define the location where the div will be shown.

Instead of having the module run in the beginning of the script, you move it
down so that it's after the INSERT part of the code, that way the number of
lines in the database will be correct.


--

//Aho
Shion [ Mi, 17 Januar 2007 21:53 ] [ ID #1598911 ]

Re: problem execution order

Aho, thanks for your reply.
Of course I could have done it with moving div around with CSS position

but I realy don't like that kind of solving this problem...
I was thinking of some Javascript that would be called at the end of
execution of the part that is making INSERT. That javascript would
refresh cart status...
J.O. Aho je napisao/la:
> luigi7up wrote:
> > Hello to everyone...
> > I'm having a little problem with displaying a number of products in my
> > shoping cart that I'm writing from scratch.
> > The structure of a site is following: INDEX.php is my main page where
> > everything else loads up. So, my shop component comes as
> > index.php?kom=shop and a little switch($kom) in at the begining of
> > index.php switches the main content. That content, in this case shop
> > component, loads into <div id='mainContent'>include ('$content')</div>.
> >
> > Every activity of shop component runs by sending task variable through
> > URL to itself where another SWITCH is. So, to add something to cart I
> > do index.php?kom=shop&task=add and it's added. It gets
> > $_POST['prod_id'] and component does function that runs SQL query
> > according to task=add.
> > I also have a little "module", in index.php, that says: "Number of
> > prod. in cart is :14". It is put directly into index.php so that it
> > could be seen no mater which component is loaded. Because of design of
> > a page this module is situated before the content of components that
> > are loaded.
> > My problem is that this module runs it's SQL query and gets number of
> > products in cart before the component shop runs insert function. So in
> > komponent shop I will have real situation from database but in my
> > module I'll have number of products that is not up-to date. I have
> > to refresh page so that cart module runs it's query again and gets real
> > numbers...
> > Do you have any idea how to get my cart module run after insert has
> > been done yet presented in HTML before shop component
> >
>
> As you already use div-tags, you can make the output from your module to use
> one too and in your CSS file you define the location where the div will be shown.
>
> Instead of having the module run in the beginning of the script, you move it
> down so that it's after the INSERT part of the code, that way the number of
> lines in the database will be correct.
>
>
> --
>
> //Aho
luigi7up [ Do, 18 Januar 2007 01:30 ] [ ID #1600270 ]

Re: problem execution order

luigi7up wrote:
> Aho, thanks for your reply.
> Of course I could have done it with moving div around with CSS position
> but I realy don't like that kind of solving this problem...
> I was thinking of some Javascript that would be called at the end of
> execution of the part that is making INSERT. That javascript would
> refresh cart status...

If you have the cart in it's own frame, thats no problem, as long as the use
has javascript enabled.
If you have only one page with everything in it, then I do suggest two methods
1. Use div and make the cart checkup last
2. Save all output to variables, when you done all that is to do, set
together the variables in a such manner that you get the final output.

There is an third option, but it will just make things more complicated for
you, use AJAX.

--

//Aho
Shion [ Do, 18 Januar 2007 07:23 ] [ ID #1600291 ]

Re: problem execution order

I solved the problem by executing includes at the beginning of
index.php and holding them up in $htmlOutput

variable. That way everything is executed before and information that
module gets from DB are "up to date"

Thanks...

J.O. Aho wrote:
> luigi7up wrote:
> > Aho, thanks for your reply.
> > Of course I could have done it with moving div around with CSS position
> > but I realy don't like that kind of solving this problem...
> > I was thinking of some Javascript that would be called at the end of
> > execution of the part that is making INSERT. That javascript would
> > refresh cart status...
>
> If you have the cart in it's own frame, thats no problem, as long as the use
> has javascript enabled.
> If you have only one page with everything in it, then I do suggest two methods
> 1. Use div and make the cart checkup last
> 2. Save all output to variables, when you done all that is to do, set
> together the variables in a such manner that you get the final output.
>
> There is an third option, but it will just make things more complicated for
> you, use AJAX.
>
> --
>
> //Aho
luigi7up [ Mo, 22 Januar 2007 12:10 ] [ ID #1604184 ]
PHP » alt.php » problem execution order

Vorheriges Thema: Extract first 100 characters from Mysql field
Nächstes Thema: Com object with PHP How to use? Here is the code