Gmail automatically sent my last email, apologies.
I am creating an order form for tickets for a list of performances at a
performing arts center.
Currently, the form is on paper, and is set up as follows:
-Title - date - time - price - soldout - quantity - total($)
-Nutcracker - Tues 10/13 - 9am - $4.00 - yes/no - ________ - ______
-Nutcracker - Tues 10/13 - 11am - $4.00 - yes/no - ________ - ______
-Mayhem P.. - Thur 01/21 - 9am - $4.00 - yes/no - ________ - ______
-Mayhem P.. - Thur 01/21 - 11am - $4.00 - yes/no - ________ - ______
-Max and... - Tues 04/21 - 9am - $4.00 - yes/no - ________ - ______
A given show may have between 1 and 4 performances, and I figured the best
way to approach this was to consider each show time for each show as an
entity. There are 19 unique titles, but given different showtimes, it
becomes 38 'shows'.
I have the shows in an array ($shows), and the details for each show in its
own array (eg. $show_01) embedded into the show array.
I need to generate a row for each show (so 38 rows), and assign quantity and
total input fields a unique name and id.
I can't seem to get my foreach loops to work, will PHP parse embedded loops?
Here is an example of my embedded arrays:
[code=shows.php]
$shows = array();
$shows['show_01'] = $show_01;
$show_01 = array();
$show_01['title'] = 'Van Cliburn Gold Medal Winner';
$show_01['date'] = 'Tues. 10/13/2009';
$show_01['time'] = '11am';
$show_01['price'] = 4.00;
$show_01['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE "0" to "1"
(without quotations).
$shows['show_02'] = $show_02;
$show_02 = array();
$show_02['title'] = 'Jack and the Beanstalk';
$show_02['date'] = 'Fri. 10/23/2009';
$show_02['time'] = '11am';
$show_02['price'] = 4.00;
$show_02['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE "0" to "1"
(without quotations).
[/code]
And here are the foreach loops I'm trying to build the rows with:
[code=order.php]
foreach ($shows as $key => $value) {
foreach ($value as $key2 => $value2) {
print '
In case you were wondering why I embedded the foreach statement, I need each
array (eg. $show_22) to display in a row, and I need PHP to build as many
rows are there are shows.
Is this something I need to have in a database to work?
Thanks!
--00163646c2e433f45d0470d07d96--
Re: Embedding foreach loops
am 10.08.2009 23:51:32 von Jonathan Tapicer
On Mon, Aug 10, 2009 at 6:44 PM, Allen McCabe wrote:
> Gmail automatically sent my last email, apologies.
>
> I am creating an order form for tickets for a list of performances at a
> performing arts center.
>
> Currently, the form is on paper, and is set up as follows:
> -Title =A0 =A0 - date =A0- time - price - soldout - quantity - total($)
> -Nutcracker - Tues 10/13 - =A09am - $4.00 - yes/no =A0- ________ - ______
> -Nutcracker - Tues 10/13 - 11am - $4.00 - yes/no =A0- ________ - ______
> -Mayhem P.. - Thur 01/21 - =A09am - $4.00 - yes/no =A0- ________ - ______
> -Mayhem P.. - Thur 01/21 - 11am - $4.00 - yes/no =A0- ________ - ______
> -Max and... - Tues 04/21 - =A09am - $4.00 - yes/no =A0- ________ - ______
>
> A given show may have between 1 and 4 performances, and I figured the bes=
t
> way to approach this was to consider each show time for each show as an
> entity. There are 19 unique titles, but given different showtimes, it
> becomes 38 'shows'.
>
> I have the shows in an array ($shows), and the details for each show in i=
ts
> own array (eg. $show_01) embedded into the show array.
>
> I need to generate a row for each show (so 38 rows), and assign quantity =
and
> total input fields a unique name and id.
>
> I can't seem to get my foreach loops to work, will PHP parse embedded loo=
ps?
>
> Here is an example of my embedded arrays:
>
> [code=3Dshows.php]
>
> $shows =3D array();
>
> =A0$shows['show_01'] =3D $show_01;
> =A0$show_01 =3D array();
> =A0$show_01['title'] =3D 'Van Cliburn Gold Medal Winner';
> =A0$show_01['date'] =3D 'Tues. 10/13/2009';
> =A0$show_01['time'] =3D '11am';
> =A0$show_01['price'] =3D 4.00;
> =A0$show_01['soldout'] =3D 0; //IF THE SHOW SELLS OUT, CHANGE "0" to "1"
> (without quotations).
>
> =A0$shows['show_02'] =3D $show_02;
> =A0$show_02 =3D array();
> =A0$show_02['title'] =3D 'Jack and the Beanstalk';
> =A0$show_02['date'] =3D 'Fri. 10/23/2009';
> =A0$show_02['time'] =3D '11am';
> =A0$show_02['price'] =3D 4.00;
> =A0$show_02['soldout'] =3D 0; //IF THE SHOW SELLS OUT, CHANGE "0" to "1"
> (without quotations).
>
> [/code]
>
> And here are the foreach loops I'm trying to build the rows with:
>
> [code=3Dorder.php]
>
>
> foreach ($shows as $key =3D> $value) {
> =A0foreach ($value as $key2 =3D> $value2) {
> =A0 =A0 =A0print ' =A0 =A0 =A0
';
> }
> ?>
>
> [/code]
>
> In case you were wondering why I embedded the foreach statement, I need e=
ach
> array (eg. $show_22) to display in a row, and I need PHP to build as many
> rows are there are shows.
>
> Is this something I need to have in a database to work?
>
> Thanks!
>
Embedded loops are OK, actually I don't know a language where you can't do =
it :)
I think that your problem is the $shows array creation, you do this:
Note that you are assigning $show_01 to a key in $shows before
creating $show_01, you should first create and fill $show_01 and then
assign it to a key in $shows.
Hope that helps.
Jonathan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 00:04:23 von Govinda
> I can't seem to get my foreach loops to work, will PHP parse
> embedded loops?
yes.
> Is this something I need to have in a database to work?
no, you can do it with the arrays... but it may be easier to work
with over the long run if that data was in a db.
Anyway right after you finish creating the array and it's embedded
arrays, in your code, then add this:
var_dump($shows); //--so you can see what you just created. If it
looks right, THEN go on bothering to try and parse it with your
(embedded) foreach's {
------------
John Butler (Govinda)
govinda.webdnatalk@gmail.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
and for reference, my original php used to set up arrays
[code=shows.php]
$shows = array();
$show_01 = array();
$show_01['title'] = 'Van Cliburn Gold Medal Winner';
$show_01['date'] = 'Tues. 10/13/2009';
$show_01['time'] = '11am';
$show_01['price'] = 4.00;
$show_01['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE "0" to "1"
(without quotations).
$shows['show_01'] = $show_01;
$show_02 = array();
$show_02['title'] = 'Jack and the Beanstalk';
$show_02['date'] = 'Fri. 10/23/2009';
$show_02['time'] = '11am';
$show_02['price'] = 4.00;
$show_02['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE "0" to "1"
(without quotations).
$shows['show_02'] = $show_02;
[/code]
Does this dump look right?
On Mon, Aug 10, 2009 at 3:04 PM, John Butler wrote:
> I can't seem to get my foreach loops to work, will PHP parse embedded
>> loops?
>>
>
> yes.
>
> Is this something I need to have in a database to work?
>>
>
> no, you can do it with the arrays... but it may be easier to work with
> over the long run if that data was in a db.
>
> Anyway right after you finish creating the array and it's embedded arrays,
> in your code, then add this:
> var_dump($shows); //--so you can see what you just created. If it looks
> right, THEN go on bothering to try and parse it with your (embedded)
> foreach's {
>
> ------------
> John Butler (Govinda)
> govinda.webdnatalk@gmail.com
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--0016364ee4e60f2a960470d11ddb--
Re: Embedding foreach loops
am 11.08.2009 00:41:51 von Govinda
> I did this, and got my arrays dumped (on one line). After adding
> line returns, here is a snippet:
it looks OK. Note that you can see (copy/paste) that array which you
just dumped, much better, if you view the source code of the html
page. OR you can use
to make that format persist thru' to what
you see without viewing the source., Like so:
echo "
\n";
var_dump($theArray);
echo "
\n";
echo "\n";
My brain is so full of my own work.. and I am newbie compared to most
lurking here.. but I am sure we'll figure out your issue if we work on
it systematically. OK, your OP just said, "..I can't seem to get my
foreach loops to work.." , but you never said exactly what is the
problem. Break the problem down to the smallest thing that you can
find that is not behaving as you expect it to, and explain THAT to
me. We'll do this step by step.
-John
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
There are a lot of alternatives if you want to remove the arrays.... XML,
ini files, text files, yaml, json
Of course... they all will implicate to open the file, read it, and then
process it.
On Mon, Aug 10, 2009 at 7:29 PM, Allen McCabe wrote:
> John,
>
> I did this, and got my arrays dumped (on one line). After adding line
> returns, here is a snippet:
>
> [code=array dump]
>
> array(38) {
> ["show_01"]=> array(5) {
> ["title"]=> string(29) "Van Cliburn Gold Medal Winner"
> ["date"]=> string(16) "Tues. 10/13/2009"
> ["time"]=> string(4) "11am"
> ["price"]=> float(4)
> ["soldout"]=> int(0)
> }
> ["show_02"]=> array(5) {
> ["title"]=> string(22) "Jack and the Beanstalk"
> ["date"]=> string(15) "Fri. 10/23/2009"
> ["time"]=> string(4) "11am"
> ["price"]=> float(4)
> ["soldout"]=> int(0)
> }
>
> [/code]
>
> and for reference, my original php used to set up arrays
>
> [code=shows.php]
>
> $shows = array();
> $show_01 = array();
> $show_01['title'] = 'Van Cliburn Gold Medal Winner';
> $show_01['date'] = 'Tues. 10/13/2009';
> $show_01['time'] = '11am';
> $show_01['price'] = 4.00;
> $show_01['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE "0" to "1"
> (without quotations).
> $shows['show_01'] = $show_01;
> $show_02 = array();
> $show_02['title'] = 'Jack and the Beanstalk';
> $show_02['date'] = 'Fri. 10/23/2009';
> $show_02['time'] = '11am';
> $show_02['price'] = 4.00;
> $show_02['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE "0" to "1"
> (without quotations).
> $shows['show_02'] = $show_02;
>
> [/code]
>
> Does this dump look right?
>
> On Mon, Aug 10, 2009 at 3:04 PM, John Butler
> wrote:
>
> > I can't seem to get my foreach loops to work, will PHP parse embedded
> >> loops?
> >>
> >
> > yes.
> >
> > Is this something I need to have in a database to work?
> >>
> >
> > no, you can do it with the arrays... but it may be easier to work with
> > over the long run if that data was in a db.
> >
> > Anyway right after you finish creating the array and it's embedded
> arrays,
> > in your code, then add this:
> > var_dump($shows); //--so you can see what you just created. If it looks
> > right, THEN go on bothering to try and parse it with your (embedded)
> > foreach's {
> >
> > ------------
> > John Butler (Govinda)
> > govinda.webdnatalk@gmail.com
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
I am using the print function to display my html. I cannot get the line
return ( \n ) character to actually push the html onto the next line, it
just gets displayed instead. Should I be using echo?
On Mon, Aug 10, 2009 at 3:41 PM, John Butler wrote:
>
> I did this, and got my arrays dumped (on one line). After adding line
>> returns, here is a snippet:
>>
>
>
> it looks OK. Note that you can see (copy/paste) that array which you just
> dumped, much better, if you view the source code of the html page. OR you
> can use
to make that format persist thru' to what you see without
> viewing the source., Like so:
>
> echo "
\n";
> var_dump($theArray);
> echo "
\n";
> echo "\n";
>
> My brain is so full of my own work.. and I am newbie compared to most
> lurking here.. but I am sure we'll figure out your issue if we work on it
> systematically. OK, your OP just said, "..I can't seem to get my foreach
> loops to work.." , but you never said exactly what is the problem. Break
> the problem down to the smallest thing that you can find that is not
> behaving as you expect it to, and explain THAT to me. We'll do this step
> by step.
>
> -John
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
And sure, you could do all this in a database, or some other sort of
external storage, but unless you're looking at creating a separate UI
for someone other than yourself to input the data, it's probably
simpler all around just to define the data directly in PHP. No reason
you couldn't upgrade to something more sophisticated down the road, if
the customer requires it.
Ben
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Embedding foreach loops
am 11.08.2009 01:18:20 von Daevid Vincent
You're not using the
and
tag most likely then.
> -----Original Message-----
> From: Allen McCabe [mailto:allenmccabe@gmail.com]
> Sent: Monday, August 10, 2009 4:11 PM
> To: John Butler
> Cc: phpList
> Subject: Re: [PHP] Embedding foreach loops
>
> I am using the print function to display my html. I cannot
> get the line
> return ( \n ) character to actually push the html onto the
> next line, it
> just gets displayed instead. Should I be using echo?
>
>
>
> On Mon, Aug 10, 2009 at 3:41 PM, John Butler
> wrote:
>
> >
> > I did this, and got my arrays dumped (on one line). After
> adding line
> >> returns, here is a snippet:
> >>
> >
> >
> > it looks OK. Note that you can see (copy/paste) that array
> which you just
> > dumped, much better, if you view the source code of the
> html page. OR you
> > can use
to make that format persist thru' to what you
> see without
> > viewing the source., Like so:
> >
> > echo "
\n";
> > var_dump($theArray);
> > echo "
\n";
> > echo "\n";
> >
> > My brain is so full of my own work.. and I am newbie
> compared to most
> > lurking here.. but I am sure we'll figure out your issue if
> we work on it
> > systematically. OK, your OP just said, "..I can't seem to
> get my foreach
> > loops to work.." , but you never said exactly what is the
> problem. Break
> > the problem down to the smallest thing that you can find that is not
> > behaving as you expect it to, and explain THAT to me.
> We'll do this step
> > by step.
> >
> > -John
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 01:22:38 von Ben Dunlap
> I am using the print function to display my html. I cannot get the line
> return ( \n ) character to actually push the html onto the next line, it
> just gets displayed instead. Should I be using echo?
In the PHP code snippet you pasted above, you're using single-quotes
to delimit your literal strings. In-between single-quotes, '\n' is not
converted to a newline character. It's interpeted completely
literally:
Also, are you looking to insert a line break into the HTML itself --
just to keep your HTML code clean -- or into the visible page that's
rendered from the HTML? Because newlines don't have any significance
in HTML. You'd need to insert a or close a block-level element
to get the effect of a line-break in the visible page.
Ben
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 01:56:20 von Govinda
> I am using the print function to display my html. I cannot get the
> line return ( \n ) character to actually push the html onto the next
> line, it just gets displayed instead. Should I be using echo?
Allen, you off and running again?
echo "blah.. \n"; //<-- this will print the literal 'blah.. ' and
then a newline into your HTML *source code*
echo 'blah.. \n'; //<-- this will print the literal 'blah.. \n' into
your HTML *source code*
IIRC print is the same as echo. That is not your apparent issue.
Say if you are stuck again, and on what exactly.
-John
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 09:03:56 von Ashley Sheridan
On Tue, 2009-08-11 at 07:13 +0000, hessiess@hessiess.com wrote:
> Do *NOT* get into the habit of outputting your HTML using echo or print
> statements, it becomes unmaintainable very quickly, use a templating
> language, ether with a framework(recomended) or standalone.
>
> You should learn the basics of HTML and CSS, go and read
> http://htmldog.com/, btw to add a newline you need to use " ".
>
> >> I am using the print function to display my html. I cannot get the
> >> line return ( \n ) character to actually push the html onto the next
> >> line, it just gets displayed instead. Should I be using echo?
> >
> >
> > Allen, you off and running again?
> >
> > echo "blah.. \n"; //<-- this will print the literal 'blah.. ' and
> > then a newline into your HTML *source code*
> > echo 'blah.. \n'; //<-- this will print the literal 'blah.. \n' into
> > your HTML *source code*
> >
> > IIRC print is the same as echo. That is not your apparent issue.
> >
> > Say if you are stuck again, and on what exactly.
> >
> > -John
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
*Or* you could use the heredoc syntax, which I'm quite a fan of.
print <<
some content here
content with a php $variable here
this gets displayed after the extra new lines in the source
EOC;
Still easy to maintain.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 09:13:00 von hessiess
Do *NOT* get into the habit of outputting your HTML using echo or print
statements, it becomes unmaintainable very quickly, use a templating
language, ether with a framework(recomended) or standalone.
You should learn the basics of HTML and CSS, go and read
http://htmldog.com/, btw to add a newline you need to use " ".
>> I am using the print function to display my html. I cannot get the
>> line return ( \n ) character to actually push the html onto the next
>> line, it just gets displayed instead. Should I be using echo?
>
>
> Allen, you off and running again?
>
> echo "blah.. \n"; //<-- this will print the literal 'blah.. ' and
> then a newline into your HTML *source code*
> echo 'blah.. \n'; //<-- this will print the literal 'blah.. \n' into
> your HTML *source code*
>
> IIRC print is the same as echo. That is not your apparent issue.
>
> Say if you are stuck again, and on what exactly.
>
> -John
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 17:21:35 von sono-io
On Aug 11, 2009, at 12:13 AM, hessiess@hessiess.com wrote:
> Do *NOT* get into the habit of outputting your HTML using echo or
> print
> statements, it becomes unmaintainable very quickly, use a templating
> language, ether with a framework(recomended) or standalone.
This sounds interesting. Could you expound on this a little more and
perhaps list a couple of the templates you mention?
Thanks,
Frank
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
> statements, it becomes unmaintainable very quickly, use a templating
> language, ether with a framework(recomended) or standalone.
But he /is/ using a templating language... PHP. ;-)
Ben
--0016363ba2125d391a0470e1e3fd--
Re: Embedding foreach loops
am 11.08.2009 21:00:53 von Robert Cummings
Ben Dunlap wrote:
>> statements, it becomes unmaintainable very quickly, use a templating
>> language, ether with a framework(recomended) or standalone.
>
>
> But he /is/ using a templating language... PHP. ;-)
Keep telling yourself that... and be sure to pat your own back.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
> statements, it becomes unmaintainable very quickly, use a templating
>>> language, ether with a framework(recomended) or standalone.
>>>
>>
>>
>> But he /is/ using a templating language... PHP. ;-)
>>
>
> Keep telling yourself that... and be sure to pat your own back.
>
I'm sure there are plenty of situations that call for a more focused
templating system than the one that PHP already is. And there are plenty
that don't.
From the earlier content of this thread, I suspect the problem the OP is
currently working on falls into the latter camp. Didn't mean to bash
templating systems.
This is probably flame-war tinder, so I'll try to tread more delicately in
the future. Next you know we'll be on the ternary operator and which is
better, Mac or Windows. ;-)
Ben
--00163646d40ab7245e0470e2edd6--
Re: Embedding foreach loops
am 11.08.2009 21:56:28 von TedD
At 12:44 PM -0700 8/11/09, Ben Dunlap wrote:
>This is probably flame-war tinder, so I'll try to tread more delicately in
>the future. Next you know we'll be on the ternary operator and which is
>better, Mac or Windows. ;-)
>
>Ben
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 22:00:14 von Eddie Drapkin
On Tue, Aug 11, 2009 at 3:56 PM, tedd wrote:
> At 12:44 PM -0700 8/11/09, Ben Dunlap wrote:
>>
>> This is probably flame-war tinder, so I'll try to tread more delicately =
in
>> the future. Next you know we'll be on the ternary operator and which is
>> better, Mac or Windows. ;-)
>>
>> Ben
>
> That was won long ago, it's Mac. :-)
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com  http://ancientstones.com  http://earthston=
es.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
If by Mac you mean Linux, you're entirely correct.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 22:04:39 von Govinda
> Allen, you off and running again?
> Sure am, thanks, on to the next set of issues. Seems like
> programming is always moving on from one error to the next :)
>
> Currently, I am having trouble with echo and php line-returns.
>
> It works on one part of the code, but not on another (instead,
> prints it to html).
>
> For example:
>
> [code]
>
> $show[show_01][price] * $show_01_qty = $Total_show_01;
> echo "\n
\n\t";
> echo "
a".$show[show_01][price]."
/n/t
*
/n/t
b".
> $show_01_qty."
/n/t
=
\n\t
c".$Total_show_01."
";
> echo "\n
";
>
> [/code]
>
> outputs this html
>
> [code]
>
>
>
a
/n/t
*
/n/t
b
/n/t
=
>
c
>
>
> [/code]
> Additionally, it won't display the variables, as you can see, even
> though they will echo out further above in the document. Odd...
well you escape a newline char with this slash:
\
and not this one:
/
notice you were not consistent with your use of them.
as for the array not being parsed inside your echo statement - I
don't see the issue by looking now. Are you saying the EXACT same
code does output the expected value for those array elements higher up
the script? Show us the code where it is working and again where it
is not.. side by side (pasted just after each other in a new post to
the list).
I assume you are past this next point, but always remember
var_dump($myArray);
is your friend. Put it just before where you try to echo out some
part of the array.. check to be sure the value is there is that
element of the multi-dimensional array the way you think it is.
-John
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 22:08:06 von hessiess
>
> On Aug 11, 2009, at 12:13 AM, hessiess@hessiess.com wrote:
>
>> Do *NOT* get into the habit of outputting your HTML using echo or
>> print
>> statements, it becomes unmaintainable very quickly, use a templating
>> language, ether with a framework(recomended) or standalone.
>
> This sounds interesting. Could you expound on this a little
more and
> perhaps list a couple of the templates you mention?
>
> Thanks,
> Frank
>
There are a number of options for templating in PHP such as smarty, Dwoo
and PHP itself, though the syntax can be rather messy. Personally I just
use a simple find and replace macro system to expand custom short-hand
code into the more verbose PHP, then run it through exec and capture the
result to a variable with output buffering, the class folows:
class view
{
var $str;
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Load in template file and expand macros into PHP
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
function __CONSTRUCT($tplname)
{
$fh = fopen($tplname, 'r');
$this->str = fread($fh, filesize($tplname));
fclose($fh);
$this->expand_macros();
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Run the template and return a variable
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
public function parse_to_variable($array = array())
{
extract($array);
the $dialogue var now contains the compiled template, ready for displaying
or integrating into another template.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 22:23:16 von Richard Duval
OK, first guys, I'm sorry to have to do this but I can't get off this list!=
!!
I've followed the instructions on a couple of occasions (the ones at
the bottom of every email):
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
Been There, done that. I can't get off the list!!! I use Gmail and I
use an an alias as well, tried them both, still on the list. No reply
from Majordomo.
Yes, I've check my spam filter for a unsubscribe confirmation (if it
sends one which I presume it's supposed to).
Headers tell me that this list is "php-general@lists.php.net". Sent
the unsubscribe emails. No replies.
Again. I apologize but have no idea what to do to get off this list!
THis is the only list server I can't seem to get off of.
Help!
On Mon, Aug 10, 2009 at 6:04 PM, John
Butler wrote:
>> I can't seem to get my foreach loops to work, will PHP parse embedded
>> loops?
>
> yes.
>
>> Is this something I need to have in a database to work?
>
> no, you can do it with the arrays... =A0but it may be easier to work with=
over
> the long run if that data was in a db.
>
> Anyway right after you finish creating the array and it's embedded arrays=
,
> in your code, then add this:
> var_dump($shows); //--so you can see what you just created. =A0If it look=
s
> right, THEN go on bothering to try and parse it with your (embedded)
> foreach's {
>
> ------------
> John Butler (Govinda)
> govinda.webdnatalk@gmail.com
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> ---------------------------------This message has been scanned for
> viruses and dangerous content byAccurate Anti-Spam Technologies.
> www.AccurateAntiSpam.com
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 11.08.2009 22:28:24 von Robert Cummings
Let me be the first to welcome you to the list!!!
Rick Duval wrote:
> OK, first guys, I'm sorry to have to do this but I can't get off this list!!!
>
> I've followed the instructions on a couple of occasions (the ones at
> the bottom of every email):
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>
> Been There, done that. I can't get off the list!!! I use Gmail and I
> use an an alias as well, tried them both, still on the list. No reply
> from Majordomo.
>
> Yes, I've check my spam filter for a unsubscribe confirmation (if it
> sends one which I presume it's supposed to).
>
> Headers tell me that this list is "php-general@lists.php.net". Sent
> the unsubscribe emails. No replies.
>
> Again. I apologize but have no idea what to do to get off this list!
> THis is the only list server I can't seem to get off of.
>
> Help!
>
>
> On Mon, Aug 10, 2009 at 6:04 PM, John
> Butler wrote:
>>> I can't seem to get my foreach loops to work, will PHP parse embedded
>>> loops?
>> yes.
>>
>>> Is this something I need to have in a database to work?
>> no, you can do it with the arrays... but it may be easier to work with over
>> the long run if that data was in a db.
>>
>> Anyway right after you finish creating the array and it's embedded arrays,
>> in your code, then add this:
>> var_dump($shows); //--so you can see what you just created. If it looks
>> right, THEN go on bothering to try and parse it with your (embedded)
>> foreach's {
>>
>> ------------
>> John Butler (Govinda)
>> govinda.webdnatalk@gmail.com
>>
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> ---------------------------------This message has been scanned for
>> viruses and dangerous content byAccurate Anti-Spam Technologies.
>> www.AccurateAntiSpam.com
>>
>>
>
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 12.08.2009 11:39:37 von Ashley Sheridan
On Tue, 2009-08-11 at 16:00 -0400, Eddie Drapkin wrote:
> On Tue, Aug 11, 2009 at 3:56 PM, tedd wrote:
> > At 12:44 PM -0700 8/11/09, Ben Dunlap wrote:
> >>
> >> This is probably flame-war tinder, so I'll try to tread more delicately in
> >> the future. Next you know we'll be on the ternary operator and which is
> >> better, Mac or Windows. ;-)
> >>
> >> Ben
> >
> > That was won long ago, it's Mac. :-)
> >
> > Cheers,
> >
> > tedd
> >
> > --
> > -------
> > http://sperling.com http://ancientstones.com http://earthstones.com
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> If by Mac you mean Linux, you're entirely correct.
>
Linux +100
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Embedding foreach loops
am 12.08.2009 11:41:19 von Ashley Sheridan
On Tue, 2009-08-11 at 16:23 -0400, Rick Duval wrote:
> OK, first guys, I'm sorry to have to do this but I can't get off this list!!!
>
> I've followed the instructions on a couple of occasions (the ones at
> the bottom of every email):
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> Been There, done that. I can't get off the list!!! I use Gmail and I
> use an an alias as well, tried them both, still on the list. No reply
> from Majordomo.
>
> Yes, I've check my spam filter for a unsubscribe confirmation (if it
> sends one which I presume it's supposed to).
>
> Headers tell me that this list is "php-general@lists.php.net". Sent
> the unsubscribe emails. No replies.
>
> Again. I apologize but have no idea what to do to get off this list!
> THis is the only list server I can't seem to get off of.
>
> Help!
>
>
> On Mon, Aug 10, 2009 at 6:04 PM, John
> Butler wrote:
> >> I can't seem to get my foreach loops to work, will PHP parse embedded
> >> loops?
> >
> > yes.
> >
> >> Is this something I need to have in a database to work?
> >
> > no, you can do it with the arrays... but it may be easier to work with over
> > the long run if that data was in a db.
> >
> > Anyway right after you finish creating the array and it's embedded arrays,
> > in your code, then add this:
> > var_dump($shows); //--so you can see what you just created. If it looks
> > right, THEN go on bothering to try and parse it with your (embedded)
> > foreach's {
> >
> > ------------
> > John Butler (Govinda)
> > govinda.webdnatalk@gmail.com
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > ---------------------------------This message has been scanned for
> > viruses and dangerous content byAccurate Anti-Spam Technologies.
> > www.AccurateAntiSpam.com
> >
> >
>
Use the unsubscribe email address that's in the header (this is very
different from the footer) of every email from the list.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php