what am i doing wrong now :(

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

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

what am i doing wrong now :(

Post by pinehead18 »

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 .= "&nbsp;"; } ."
</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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

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.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

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.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

I like markl999's answer better. Nice style.
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

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 »

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 :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's called a heredoc.
Post Reply