Page 1 of 2

[SOVLED] A PROBLEM WITH HEREDOC?!?!?!?!?!

Posted: Mon Jan 12, 2004 5:37 pm
by dull1554
heres my code

Code: Select all

$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{
Print <<< EOS
<tr><a href=$_POST[LU_$the_num_num]>
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'>$_POST[LT_$the_num_num]</font></center></td></a>
</tr>
EOS;


$the_num_num++;
$the_num++;
}
heres what i need to have

Code: Select all

$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{

Print <<< EOS
<tr><a href=$_POST['LU_$the_num_num']>//added 2 single quotes
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'>$_POST[LT_$the_num_num]</font></center></td></a>//added 2 single quotes
</tr>
EOS;


$the_num_num++;
$the_num++;
}
when i try the second bit of code i get this error

Code: Select all

Parse error: parse error, unexpected T_VARIABLE, expecting ']' in c:\program files\apache group\apache\htdocs\test\menu\step3.php on line 22
i need to be able to have those quotes in there, but if i put them there everything goes all to hell

Re: A PROBLEM WITH HEREDOC?!?!?!?!?!

Posted: Mon Jan 12, 2004 6:21 pm
by Straterra
dull1554 wrote:heres my code

Code: Select all

$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{
Print <<< EOS
<tr><a href=$_POST[LU_$the_num_num]>
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'>$_POST[LT_$the_num_num]</font></center></td></a>
</tr>
EOS;


$the_num_num++;
$the_num++;
}
heres what i need to have

Code: Select all

$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{

Print <<< EOS
<tr><a href=$_POST['LU_$the_num_num']>//added 2 single quotes
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'>$_POST[LT_$the_num_num]</font></center></td></a>//added 2 single quotes
</tr>
EOS;


$the_num_num++;
$the_num++;
}
when i try the second bit of code i get this error

Code: Select all

Parse error: parse error, unexpected T_VARIABLE, expecting ']' in c:\program files\apache group\apache\htdocs\test\menu\step3.php on line 22
i need to be able to have those quotes in there, but if i put them there everything goes all to hell

Try this

Code: Select all

<?php
$the_num_num = "1";
$the_num = "0";

while($_GET['number_of_links']>$the_num)
{
Print
?>
<tr><a href="<?php echo $_POST['LU_$the_num_num']; ?>">
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'>
<center><font style='color:black'><?php echo $_POST['LT_$the_num_num']; ?></font></center></td></a>
</tr>
<?php
$the_num_num++;
$the_num++;
}
?>

Posted: Mon Jan 12, 2004 6:26 pm
by dull1554
i hate to say it but that did not work either, i just don't understand what i have to do to get this to work correctly

Posted: Mon Jan 12, 2004 6:29 pm
by Straterra
What error did you get when you used my code?

Posted: Mon Jan 12, 2004 6:30 pm
by dull1554

Code: Select all

Parse error: parse error, unexpected '<' in c:\program files\apache group\apache\htdocs\test\menu\step3.php on line 22

Posted: Mon Jan 12, 2004 6:30 pm
by dull1554
may the force be with you

Posted: Mon Jan 12, 2004 6:33 pm
by Straterra

Code: Select all

<?php 
$the_num_num = "1"; 
$the_num = "0"; 

while($_GET['number_of_links']>$the_num) 
{ 
?>
<tr><a href="<?php echo $_POST['LU_$the_num_num']; ?>"> 
<td onMouseover='this.bgColor=#C0C0C0' onMouseout='this.bgColor=transparent' width='90' align='center'> 
<center><font style='color:black'><?php echo $_POST['LT_$the_num_num']; ?> </font></center></td></a> 
</tr> 
<?php 
$the_num_num++; 
$the_num++; 
} 
?>
Try this.

NOTE : I eddited the

Code: Select all

&lt;tr&gt;&lt;a href="&lt;?php echo $_POST&#1111;'LU_$the_num_num']; ?&gt;"&gt;
Line from post..Make sure you use this line!!

Posted: Mon Jan 12, 2004 6:49 pm
by dull1554
thanks, its a bit closer

Posted: Mon Jan 12, 2004 6:51 pm
by Straterra
What other errors?

Posted: Mon Jan 12, 2004 7:18 pm
by McGruff
Personally I don't like mixing up html with php.

For the sake of clarity it's important to keep presentation separate from the task of defining vars to be output on a page: eg php scripts do all the business logic first, then print vars by including html templates.

Mixing html up with php also limits your output options. If instead your script defines a bunch of unformatted vars, you are free to output them in any format you like.

And it's hard to work on page layout & graphical design without user-friendly, script-free templates.

Posted: Mon Jan 12, 2004 8:05 pm
by Straterra
Yeah, but I personally find it easer to mix PHP and HTML..I use a program that syntax highlited both PHP and HTML, so getting mixed up isn't really a problem for me personally.

Posted: Mon Jan 12, 2004 9:13 pm
by Pyrite
Wondering why Nay hasn't seen this post yet .. he'll school us on heredoc.

Posted: Tue Jan 13, 2004 1:38 am
by devork
btw where is nay :roll:
wake up nay.
or you want someone else to answer it?

Code: Select all

<?php
$collections =<<<EOD
Your html goes here
EOD;
?>
this is the example I refer while using heredocs. :)

Posted: Tue Jan 13, 2004 2:48 am
by Nay
You need not fear now, the master has come :). You can't print arrays like that in heredoc. Use { and } for arrays. Example:

Wrong:

Code: Select all

<?php

echo <<< THAT
$_POST['name']
THAT;

?>
Right:

Code: Select all

<?php

echo <<< THAT
{$_POST['name']}
THAT;

?>
Got me? ;)

On the other note, it also can be used with variables when you want to print somewhat as:

Code: Select all

<?php

$item = "butt";
$action = "burn";

echo <<< THAT
my {$item}'s {$action}ed <_<
THAT;

// which will output: my butt's burned <_<

?>
-Nay

Posted: Tue Jan 13, 2004 6:55 pm
by qads
lol..i knew you couldt resist a heredoc topic nay :P