470,815 Members | 1,154 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Re: Pre-Analyze a PHP page?

Mo wrote:
I'm a novice looking for suggestions.

I have a report which is now working how I want it, but I need to add
some calculated totals.
The problem is that I need to put the sum of detail above (prior to)
the detail itself.

Is there a way to pre-analyze the page or something so that I can use
the sum prior to the getting the parts that make the sum?
Instead of echo()ing everything, store it in a string variable. Then, sum
what you need to, then echo() the sum, then echo() the string holding the
(delayed) output.

Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

A Tale of Two Cities LITE(tm)
-- by Charles Dickens

A man in love with a girl who loves another man who looks just
like him has his head chopped off in France because of a mean
lady who knits.

Crime and Punishment LITE(tm)
-- by Fyodor Dostoevski

A man sends a nasty letter to a pawnbroker, but later
feels guilty and apologizes.

The Odyssey LITE(tm)
-- by Homer

After working late, a valiant warrior gets lost on his way home.

Jun 27 '08 #1
16 1075
Mo
On Jun 11, 12:11*pm, Ivn Snchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Mo wrote:
I'm a novice looking for suggestions.
I have a report which is now working how I want it, but I need to add
some calculated totals.
The problem is that I need to put the sum of detail above (prior to)
the detail itself.
Is there a way to pre-analyze the page or something so that I can use
the sum prior to the getting the parts that make the sum?

Instead of echo()ing everything, store it in a string variable. Then, sum
what you need to, then echo() the sum, then echo() the string holding the
(delayed) output.

Cheers,
--
----------------------------------
Ivn Snchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

A Tale of Two Cities LITE(tm)
* * * * -- by Charles Dickens

* * * * A man in love with a girl who loves another man who looks just
* * * * like him has his head chopped off in France because of a mean
* * * * lady who knits.

Crime and Punishment LITE(tm)
* * * * -- by Fyodor Dostoevski

* * * * A man sends a nasty letter to a pawnbroker, but later
* * * * feels guilty and apologizes.

The Odyssey LITE(tm)
* * * * -- by Homer

* * * * After working late, a valiant warrior gets lost on his wayhome.
I don't think I can just store it into a variable for delayed output
because it has to be in the WHILE loop for it to itterate correctly.
If I'm wrong on this, PLEASE correct me.
I'd love to be able to do it this way (i tried something like this,
but couldn't get it to work).

~Mo
Jun 27 '08 #2
Mo wrote:
I don't think I can just store it into a variable for delayed output
because it has to be in the WHILE loop for it to itterate correctly.
If I'm wrong on this, PLEASE correct me.
You're wrong.

It should work like this:

<?php
$output='';

while($condition)
{
$output .= "Whatever";
}

echo $output;
?>

Note the use of the .= operator, check the PHP manual if you have any doubts
about how .= works.

Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
Jun 27 '08 #3
Mo wrote:
On Jun 11, 12:11 pm, Ivn Snchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>Mo wrote:
>>I'm a novice looking for suggestions.
I have a report which is now working how I want it, but I need to add
some calculated totals.
The problem is that I need to put the sum of detail above (prior to)
the detail itself.
Is there a way to pre-analyze the page or something so that I can use
the sum prior to the getting the parts that make the sum?
Instead of echo()ing everything, store it in a string variable. Then, sum
what you need to, then echo() the sum, then echo() the string holding the
(delayed) output.

Cheers,
--
----------------------------------
Ivn Snchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

A Tale of Two Cities LITE(tm)
-- by Charles Dickens

A man in love with a girl who loves another man who looks just
like him has his head chopped off in France because of a mean
lady who knits.

Crime and Punishment LITE(tm)
-- by Fyodor Dostoevski

A man sends a nasty letter to a pawnbroker, but later
feels guilty and apologizes.

The Odyssey LITE(tm)
-- by Homer

After working late, a valiant warrior gets lost on his way home.

I don't think I can just store it into a variable for delayed output
because it has to be in the WHILE loop for it to itterate correctly.
If I'm wrong on this, PLEASE correct me.
I'd love to be able to do it this way (i tried something like this,
but couldn't get it to work).

~Mo
Ivn is correct. With proper programming, you can do this rather easily.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #4
Mo
On Jun 11, 8:38*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mo wrote:
On Jun 11, 12:11 pm, Ivn Snchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Mo wrote:
I'm a novice looking for suggestions.
I have a report which is now working how I want it, but I need to add
some calculated totals.
The problem is that I need to put the sum of detail above (prior to)
the detail itself.
Is there a way to pre-analyze the page or something so that I can use
the sum prior to the getting the parts that make the sum?
Instead of echo()ing everything, store it in a string variable. Then, sum
what you need to, then echo() the sum, then echo() the string holding the
(delayed) output.
Cheers,
--
----------------------------------
Ivn Snchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
A Tale of Two Cities LITE(tm)
* * * * -- by Charles Dickens
* * * * A man in love with a girl who loves another man who looks just
* * * * like him has his head chopped off in France because of a mean
* * * * lady who knits.
Crime and Punishment LITE(tm)
* * * * -- by Fyodor Dostoevski
* * * * A man sends a nasty letter to a pawnbroker, but later
* * * * feels guilty and apologizes.
The Odyssey LITE(tm)
* * * * -- by Homer
* * * * After working late, a valiant warrior gets lost on his way home.
I don't think I can just store it into a variable for delayed output
because it has to be in the WHILE loop for it to itterate correctly.
If I'm wrong on this, PLEASE correct me.
I'd love to be able to do it this way (i tried something like this,
but couldn't get it to work).
~Mo

Ivn is correct. *With proper programming, you can do this rather easily.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
WOW!
That's great!

I think I understand how the .= operator works, but I'm not quite
grasping the logic.
I am hoping that the manual has some examples, but I can't pull it up
in the manual (I'm using the online version).
If you could provide some tips on how to find it (and/or point me to
some examples), it'd be greatly appreciated.

~Mo
Jun 27 '08 #5
Mo schreef:
On Jun 11, 8:38 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Mo wrote:
>>On Jun 11, 12:11 pm, Ivn Snchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Mo wrote:
I'm a novice looking for suggestions.
I have a report which is now working how I want it, but I need to add
some calculated totals.
The problem is that I need to put the sum of detail above (prior to)
the detail itself.
Is there a way to pre-analyze the page or something so that I can use
the sum prior to the getting the parts that make the sum?
Instead of echo()ing everything, store it in a string variable. Then, sum
what you need to, then echo() the sum, then echo() the string holding the
(delayed) output.
Cheers,
--
----------------------------------
Ivn Snchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
A Tale of Two Cities LITE(tm)
-- by Charles Dickens
A man in love with a girl who loves another man who looks just
like him has his head chopped off in France because of a mean
lady who knits.
Crime and Punishment LITE(tm)
-- by Fyodor Dostoevski
A man sends a nasty letter to a pawnbroker, but later
feels guilty and apologizes.
The Odyssey LITE(tm)
-- by Homer
After working late, a valiant warrior gets lost on his way home.
I don't think I can just store it into a variable for delayed output
because it has to be in the WHILE loop for it to itterate correctly.
If I'm wrong on this, PLEASE correct me.
I'd love to be able to do it this way (i tried something like this,
but couldn't get it to work).
~Mo
Ivn is correct. With proper programming, you can do this rather easily.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

WOW!
That's great!

I think I understand how the .= operator works, but I'm not quite
grasping the logic.
Hi,

..= is just a shothand.
$myVar = "hello";
$myVar = $myVar." Mo";
echo $myVar;

is the same as:
$myVar = "hello";
$myVar .= " Mo";
echo $myVar;

Both will echo: "hello Mo"

It is called string concatination (glueing of strings).

I am hoping that the manual has some examples, but I can't pull it up
in the manual (I'm using the online version).
Online version is great. Everything you need is in there.
Just get familiar with it. :-)

If you could provide some tips on how to find it (and/or point me to
some examples), it'd be greatly appreciated.
Use the search.
If you know a functionname, just type it in, and set the select on
'functions'.

If you don't know how something is named, well, that is more difficult.
Best is to browse a little through the manual.
Start here: http://nl3.php.net/manual/en/index.php

Good luck.

Regards,
Erwin Moller
>
~Mo
Jun 27 '08 #6
Mo
On Jun 12, 9:28*am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Mo schreef:


On Jun 11, 8:38 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mo wrote:
On Jun 11, 12:11 pm, Ivn Snchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Mo wrote:
I'm a novice looking for suggestions.
I have a report which is now working how I want it, but I need to add
some calculated totals.
The problem is that I need to put the sum of detail above (prior to)
the detail itself.
Is there a way to pre-analyze the page or something so that I can use
the sum prior to the getting the parts that make the sum?
Instead of echo()ing everything, store it in a string variable. Then,sum
what you need to, then echo() the sum, then echo() the string holdingthe
(delayed) output.
Cheers,
--
----------------------------------
Ivn Snchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
A Tale of Two Cities LITE(tm)
* * * * -- by Charles Dickens
* * * * A man in love with a girl who loves another man who looks just
* * * * like him has his head chopped off in France because of a mean
* * * * lady who knits.
Crime and Punishment LITE(tm)
* * * * -- by Fyodor Dostoevski
* * * * A man sends a nasty letter to a pawnbroker, but later
* * * * feels guilty and apologizes.
The Odyssey LITE(tm)
* * * * -- by Homer
* * * * After working late, a valiant warrior gets lost on his way home.
I don't think I can just store it into a variable for delayed output
because it has to be in the WHILE loop for it to itterate correctly.
If I'm wrong on this, PLEASE correct me.
I'd love to be able to do it this way (i tried something like this,
but couldn't get it to work).
~Mo
Ivn is correct. *With proper programming, you can do this rather easily.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
WOW!
That's great!
I think I understand how the .= operator works, but I'm not quite
grasping the logic.

Hi,

.= is just a shothand.
$myVar = "hello";
$myVar = $myVar." Mo";
echo $myVar;

is the same as:
$myVar = "hello";
$myVar .= " Mo";
echo $myVar;

Both will echo: "hello Mo"

It is called string concatination (glueing of strings).
I am hoping that the manual has some examples, but I can't pull it up
in the manual (I'm using the online version).

Online version is great. Everything you need is in there.
Just get familiar with it. :-)
If you could provide some tips on how to find it (and/or point me to
some examples), it'd be greatly appreciated.

Use the search.
If you know a functionname, just type it in, and set the select on
'functions'.

If you don't know how something is named, well, that is more difficult.
Best is to browse a little through the manual.
Start here:http://nl3.php.net/manual/en/index.php

Good luck.

Regards,
Erwin Moller


~Mo- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Thanks.
I understand the logic and use of .= concatination, I'm hoping for an
example on this application of it.

Any advise?
Jun 27 '08 #7
..oO(Mo)
>I understand the logic and use of .= concatination, I'm hoping for an
example on this application of it.

Any advise?
Instead of directly printing out all the stuff you want to appear in the
browser with a bunch of echo or print statements, you simple write it to
a variable instead. Compare these two examples:

Direct print:

print 'foo';
print 'bar';
print 'something else';

With every print statement the data is immediately returned to the
browser and shown to the user (let aside output buffering, but that's a
different topic and doesn't matter here).

Now the delayed print:

$content = 'foo';
$content .= 'bar';
$content .= 'something else';

Until now nothing was returned to the browser, all the data was just
collected in the $content variable. The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator. To return all the data at once to the browser
just do

print $content;

The result in the browser will be the same, just the way how it was
created on the server is different. With the second way you have more
control over the output and more flexibility in your application logic.

HTH
Micha
Jun 27 '08 #8
On Jun 12, 3:33 pm, Michael Fesser <neti...@gmx.dewrote:

Just an off-top add, guys:
The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator.
Concatenation (this one) on PHP really means *append*? Or does it
assigns all the content of the variable plus the concatenated str?

for example:

$var = 'abc';
$var .= 'd';
//means this?
$var = 'abcd';
Thiago
Jun 27 '08 #9
..oO(Thiago Macedo)
>On Jun 12, 3:33 pm, Michael Fesser <neti...@gmx.dewrote:

Just an off-top add, guys:
>The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator.

Concatenation (this one) on PHP really means *append*? Or does it
assigns all the content of the variable plus the concatenated str?
Does it make any difference? The result is the same.

The '.' concatenates two strings and returns the result, that's all.
It doesn't really matter how the engine handles this internally.
>for example:

$var = 'abc';
$var .= 'd';
//means this?
$var = 'abcd';
Yes.

Micha
Jun 27 '08 #10
On Jun 12, 4:17 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(Thiago Macedo)
On Jun 12, 3:33 pm, Michael Fesser <neti...@gmx.dewrote:
Just an off-top add, guys:
The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator.
Concatenation (this one) on PHP really means *append*? Or does it
assigns all the content of the variable plus the concatenated str?

Does it make any difference? The result is the same.

The '.' concatenates two strings and returns the result, that's all.
It doesn't really matter how the engine handles this internally.
for example:
$var = 'abc';
$var .= 'd';
//means this?
$var = 'abcd';

Yes.

Micha
Micha,

Makes a lot of difference when you are considering performance issues.
In a 4 char string there's no problem. But in (much) larger variables
this could really be a disadvantage.
Imagine a loop setting a 100k (increasing) variable for 1000 regs. in
the end of the loop, the script had transfered around almost 100M of
memory.

I think this is not the topic case, so the 'off-topic'.

Thiago
Jun 27 '08 #11
Thiago Macedo <th**********@gmail.comwrote:
>
Makes a lot of difference when you are considering performance issues.
In a 4 char string there's no problem. But in (much) larger variables
this could really be a disadvantage.
Imagine a loop setting a 100k (increasing) variable for 1000 regs. in
the end of the loop, the script had transfered around almost 100M of
memory.
So what? Your processor can manipulate 100 megabytes of strings in much
less time than the network overhead. You seem to be optimizing too early.

However, if it really bothers you, you can certainly run through the query
twice: once to do the sum, once to print the detail records.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 27 '08 #12
Thiago Macedo wrote:
On Jun 12, 4:17 pm, Michael Fesser <neti...@gmx.dewrote:
>.oO(Thiago Macedo)
>>On Jun 12, 3:33 pm, Michael Fesser <neti...@gmx.dewrote:
Just an off-top add, guys:
The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator.
Concatenation (this one) on PHP really means *append*? Or does it
assigns all the content of the variable plus the concatenated str?
Does it make any difference? The result is the same.

The '.' concatenates two strings and returns the result, that's all.
It doesn't really matter how the engine handles this internally.
>>for example:
$var = 'abc';
$var .= 'd';
//means this?
$var = 'abcd';
Yes.

Micha

Micha,

Makes a lot of difference when you are considering performance issues.
In a 4 char string there's no problem. But in (much) larger variables
this could really be a disadvantage.
Imagine a loop setting a 100k (increasing) variable for 1000 regs. in
the end of the loop, the script had transfered around almost 100M of
memory.
The engine does optimise this internally, you don't need to worry about
X number of 'unfinished' strings lingering in memory, that won't happen
(unless you keep a reference to them with a variable). You can of course
check for yourself by taking a large string, fiddle with it and report
memory usage in between). Building a large string does take that memory
though, but in an HTTP context, if your strings gets into the MB's, you
have an whole other problem...
--
Rik Wasmus
....spamrun finished
Jun 27 '08 #13
Mo
On Jun 12, 11:33 am, Michael Fesser <neti...@gmx.dewrote:
.oO(Mo)
I understand the logic and use of .= concatination, I'm hoping for an
example on this application of it.
Any advise?

Instead of directly printing out all the stuff you want to appear in the
browser with a bunch of echo or print statements, you simple write it to
a variable instead. Compare these two examples:

Direct print:

print 'foo';
print 'bar';
print 'something else';

With every print statement the data is immediately returned to the
browser and shown to the user (let aside output buffering, but that's a
different topic and doesn't matter here).

Now the delayed print:

$content = 'foo';
$content .= 'bar';
$content .= 'something else';

Until now nothing was returned to the browser, all the data was just
collected in the $content variable. The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator. To return all the data at once to the browser
just do

print $content;

The result in the browser will be the same, just the way how it was
created on the server is different. With the second way you have more
control over the output and more flexibility in your application logic.

HTH
Micha
Thanks Micha,

Your post did help fortify my understanding of the .= concatenation,
but I'm still struggling with applying it in a way that gets the
queries out of the WHILE loops, while still getting it to iterate
through properly?
(as I'm understanding it, this, ultimately, is what's being advised.)

I have three layers of looping for three queries.
The totals for all three levels rely on the inner-most loop.
I can get the totals for the two sub-loops, but can't figure out how
to get the totals for the primary loop.

Here's the structure I have in mind:
$qryONE = select * from tableA
WHILE(idA) // loopONE
{
$qryTWO = select * from tableB
print ValueA
print SumOfB // (which is sum of C's)
}
WHILE(idB) // loopTWO
{
$qryTHREE = select * from tableC
print ValueB
print SumOfC's
}
WHILE(idC) // loopTHREE
{
print "ValueC" . "SumOfC"
}

Is there a better way of doing it?
~Mo
Jun 27 '08 #14
Mo
On Jun 13, 9:15 am, Mo <Mehile.Orl...@gmail.comwrote:
On Jun 12, 11:33 am, Michael Fesser <neti...@gmx.dewrote:
.oO(Mo)
>I understand the logic and use of .= concatination, I'm hoping for an
>example on this application of it.
>Any advise?
Instead of directly printing out all the stuff you want to appear in the
browser with a bunch of echo or print statements, you simple write it to
a variable instead. Compare these two examples:
Direct print:
print 'foo';
print 'bar';
print 'something else';
With every print statement the data is immediately returned to the
browser and shown to the user (let aside output buffering, but that's a
different topic and doesn't matter here).
Now the delayed print:
$content = 'foo';
$content .= 'bar';
$content .= 'something else';
Until now nothing was returned to the browser, all the data was just
collected in the $content variable. The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator. To return all the data at once to the browser
just do
print $content;
The result in the browser will be the same, just the way how it was
created on the server is different. With the second way you have more
control over the output and more flexibility in your application logic.
HTH
Micha

Thanks Micha,

Your post did help fortify my understanding of the .= concatenation,
but I'm still struggling with applying it in a way that gets the
queries out of the WHILE loops, while still getting it to iterate
through properly?
(as I'm understanding it, this, ultimately, is what's being advised.)

I have three layers of looping for three queries.
The totals for all three levels rely on the inner-most loop.
I can get the totals for the two sub-loops, but can't figure out how
to get the totals for the primary loop.

Here's the structure I have in mind:
$qryONE = select * from tableA
WHILE(idA) // loopONE
{
$qryTWO = select * from tableB
print ValueA
print SumOfB // (which is sum of C's)}

WHILE(idB) // loopTWO
{
$qryTHREE = select * from tableC
print ValueB
print SumOfC's}

WHILE(idC) // loopTHREE
{
print "ValueC" . "SumOfC"

}

Is there a better way of doing it?
~Mo
For anyone who may be interested, I've discovered my solution:
Have output AFTER closing tags of sub-loops.

IE:
WHILE() // main grouping
{
--WHILE() // aggregate info
--{
----WHILE() // detail info
----{
---- sum of detail
----}
-- sum of aggregate
--}
output table
Group
Aggregate
Detail
end table
}

~Mo
Jun 27 '08 #15
Mo wrote:
On Jun 13, 9:15 am, Mo <Mehile.Orl...@gmail.comwrote:
>On Jun 12, 11:33 am, Michael Fesser <neti...@gmx.dewrote:
>>.oO(Mo)
I understand the logic and use of .= concatination, I'm hoping for an
example on this application of it.
Any advise?
Instead of directly printing out all the stuff you want to appear in the
browser with a bunch of echo or print statements, you simple write it to
a variable instead. Compare these two examples:
Direct print:
print 'foo';
print 'bar';
print 'something else';
With every print statement the data is immediately returned to the
browser and shown to the user (let aside output buffering, but that's a
different topic and doesn't matter here).
Now the delayed print:
$content = 'foo';
$content .= 'bar';
$content .= 'something else';
Until now nothing was returned to the browser, all the data was just
collected in the $content variable. The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator. To return all the data at once to the browser
just do
print $content;
The result in the browser will be the same, just the way how it was
created on the server is different. With the second way you have more
control over the output and more flexibility in your application logic.
HTH
Micha
Thanks Micha,

Your post did help fortify my understanding of the .= concatenation,
but I'm still struggling with applying it in a way that gets the
queries out of the WHILE loops, while still getting it to iterate
through properly?
(as I'm understanding it, this, ultimately, is what's being advised.)

I have three layers of looping for three queries.
The totals for all three levels rely on the inner-most loop.
I can get the totals for the two sub-loops, but can't figure out how
to get the totals for the primary loop.

Here's the structure I have in mind:
$qryONE = select * from tableA
WHILE(idA) // loopONE
{
$qryTWO = select * from tableB
print ValueA
print SumOfB // (which is sum of C's)}

WHILE(idB) // loopTWO
{
$qryTHREE = select * from tableC
print ValueB
print SumOfC's}

WHILE(idC) // loopTHREE
{
print "ValueC" . "SumOfC"

}

Is there a better way of doing it?
~Mo

For anyone who may be interested, I've discovered my solution:
Have output AFTER closing tags of sub-loops.

IE:
WHILE() // main grouping
{
--WHILE() // aggregate info
--{
----WHILE() // detail info
----{
---- sum of detail
----}
-- sum of aggregate
--}
output table
Group
Aggregate
Detail
end table
}

~Mo
Which is what people have been trying to tell you to do all along...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #16
Mo
On Jun 17, 7:51 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mo wrote:
On Jun 13, 9:15 am, Mo <Mehile.Orl...@gmail.comwrote:
On Jun 12, 11:33 am, Michael Fesser <neti...@gmx.dewrote:
>.oO(Mo)
I understand the logic and use of .= concatination, I'm hoping for an
example on this application of it.
Any advise?
Instead of directly printing out all the stuff you want to appear in the
browser with a bunch of echo or print statements, you simple write it to
a variable instead. Compare these two examples:
Direct print:
print 'foo';
print 'bar';
print 'something else';
With every print statement the data is immediately returned to the
browser and shown to the user (let aside output buffering, but that's a
different topic and doesn't matter here).
Now the delayed print:
$content = 'foo';
$content .= 'bar';
$content .= 'something else';
Until now nothing was returned to the browser, all the data was just
collected in the $content variable. The first statement directly assigns
the value 'foo' to it, the two following just append new data with the
concatenation operator. To return all the data at once to the browser
just do
print $content;
The result in the browser will be the same, just the way how it was
created on the server is different. With the second way you have more
control over the output and more flexibility in your application logic.
HTH
Micha
Thanks Micha,
Your post did help fortify my understanding of the .= concatenation,
but I'm still struggling with applying it in a way that gets the
queries out of the WHILE loops, while still getting it to iterate
through properly?
(as I'm understanding it, this, ultimately, is what's being advised.)
I have three layers of looping for three queries.
The totals for all three levels rely on the inner-most loop.
I can get the totals for the two sub-loops, but can't figure out how
to get the totals for the primary loop.
Here's the structure I have in mind:
$qryONE = select * from tableA
WHILE(idA) // loopONE
{
$qryTWO = select * from tableB
print ValueA
print SumOfB // (which is sum of C's)}
WHILE(idB) // loopTWO
{
$qryTHREE = select * from tableC
print ValueB
print SumOfC's}
WHILE(idC) // loopTHREE
{
print "ValueC" . "SumOfC"
}
Is there a better way of doing it?
~Mo
For anyone who may be interested, I've discovered my solution:
Have output AFTER closing tags of sub-loops.
IE:
WHILE() // main grouping
{
--WHILE() // aggregate info
--{
----WHILE() // detail info
----{
---- sum of detail
----}
-- sum of aggregate
--}
output table
Group
Aggregate
Detail
end table
}
~Mo

Which is what people have been trying to tell you to do all along...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Oh ... I must truly be daft, because I didn't get that at all.
Upon re-reading it, I can kinda see how that is what was being
suggested.

My 0.02:
Plain English would have been much more dummy-proof.
(ie: "move your output to after your subloop(s), but still within the
parent loop(s).")
I think you guys may not realize how elementary this newbie can be.

~Mo
Jun 27 '08 #17

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Alan Illeman | last post: by
2 posts views Thread by Buck Turgidson | last post: by
5 posts views Thread by Michael Shell | last post: by
8 posts views Thread by Jarno Suni not | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.