PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Tue Aug 10, 2004 4:16 pm
Code: Select all
<?php
$topic_table .= "
<table class="table2"
<tr>
<td width=90% valign=top bgcolor=#CDCDCD>$author | : $cdate | Posted By:<a
href=http://www.kcchristians.com/myprofile/$author/>$author</a>
Posts: $posts</td><td align=right width=10%>
". if ($admin == 1) $topic_table .= "Delete Thread
- Edit"; } { $topic_table .= " "; } ."
</td></tr><tr><td width=100%>". nl2br($body) ."<br>
</td>
</tr>
</table>
";
?>
Erroring out on me where the ". if starts. "
thank you for your help and for understanding my grand newby ness
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Aug 10, 2004 4:49 pm
I prefer doing it like:
Code: Select all
<?php
$edit = ($admin == 1) ? 'Delete Thread - Edit' : ' ';
$body = nl2br($body);
$topic_table .= <<< EOD
<table class="table2"
<tr>
<td width="90%" valign="top" bgcolor="#CDCDCD">
$author | : $cdate | Posted By:<a href="http://www.kcchristians.com/myprofile/{$author}/">{$author}</a>
Posts: {$posts}
</td>
<td align="right" width="10%">{$edit}</td>
</tr>
<tr>
<td width="100%">{$body}<br></td>
</tr>
</table>
EOD;
Last edited by
markl999 on Tue Aug 10, 2004 4:50 pm, edited 1 time in total.
Buddha443556
Forum Regular
Posts: 873 Joined: Fri Mar 19, 2004 1:51 pm
Post
by Buddha443556 » Tue Aug 10, 2004 4:49 pm
Try a ternary operator:
Code: Select all
<?php
$topic_table .= "
<table class="table2"
<tr>
<td width=90% valign=top bgcolor=#CDCDCD>$author | : $cdate | Posted By:<a
href=http://www.kcchristians.com/myprofile/$author/>$author</a>
Posts: $posts</td><td align=right width=10%>
". ($admin == 1 ? "Delete Thread - Edit" : " " ) ."
</td></tr><tr><td width=100%>". nl2br($body) ."<br>
</td>
</tr>
</table>
";
?>
"if" is a control statement and doesn't really belong in the middle of a string.
Buddha443556
Forum Regular
Posts: 873 Joined: Fri Mar 19, 2004 1:51 pm
Post
by Buddha443556 » Tue Aug 10, 2004 4:51 pm
I like markl999's answer better. Nice style.
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Tue Aug 10, 2004 5:20 pm
still getting this error arse error: parse error, unexpected T_IF
Thank you
Anthony
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Wed Aug 11, 2004 11:05 am
What is this EOD method being used? Do you have any documentation anywhere on it?
I swear everytime i turn around their is a new way of doing things
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 11, 2004 11:42 am
it's called a heredoc.