准备好的PHP语句没有打印出来

时间:2014-01-07 15:44:17

标签: php html css variables

我有一个声明,它从数据库中获取信息,然后在完全准备好后打印出来。但出于某种原因,我的脚本没有打印出信息。我有这个if语句:

if($community == ''){ print $community . "\n\n" . "END" . "\n"; } else { print $community; echo "hi";}

在运行时打印出来:

  
    

()写道:

  

但这就是打印出来的全部内容。那是来自第8个$ community。= line。所以,我的问题是,为什么它只打印出来()写道:而不是所有的变量呢?

//  and ticker_symbol ='".$sym."'
    $c_sql = "SELECT message_id, subject, author, FROM_UNIXTIME(datestamp,'%m-%d-%Y') AS formatted_datestamp, forum_id, body, thread, user_id FROM phorum_messages WHERE user_id=13423720 ORDER BY datestamp DESC LIMIT 5";
    $c_result = mysql_query($c_sql,$connection) or die("Couldn't execute get query");

    // Declare Variables
    $body                   = $c_result['body'];
    $forum_id               = $c_result['forum_id'];
    $user_id                = $c_result['user_id'];
    $author                 = $c_result['author'];
    $formatted_datestamp    = $c_result['formatted_datestamp'];

    // Prepare the statement
    if ($c_result != "")  {
        $community .=  $forumPost = '<<<ENDL '. "\n";
        $community .= $body . "\n";
        $community .= 'ENDL;' . "\n";
        $community .= '$forumPost = stripBBCode(strip_tags($forumPost));' . "\n";
        $community .=  "\n";
        $community .= '<div class="comment">' . "\n";
        $community .= '<table cellspacing="0" cellpadding="0" border="0" class="reply"><tbody><tr>' . "\n";
        $community .= '<td width="90%"><b><a href="/emerging/forum/read.php?'.$forum_id.','.$user_id.'">'.$author.'</a> ('.$formatted_datestamp.') wrote:</b><br />' . "\n";
        $community .= '<p>'.iconv("ISO-8859-1//TRANSLIT", "UTF-8", $forumPost).'</p></td>' . "\n";

        $community .= '</tr></tbody></table>'. "\n";
        $community .= '</div>' . "\n";
    }

    // Print out the prepared statement
    if($community = ''){ print $community . "\n\n" . "END" . "\n"; } else { print $community;}

3 个答案:

答案 0 :(得分:2)

当您致电if($community = ''){时,您只有一个等号,将$community设置为空白字符串。

我认为你的意思是if($community == ''){

答案 1 :(得分:0)

它应该具有双等于:

if($community == '')

使用单个=符号,您只需将空字符串分配给变量$community - 然后检查它是否为true。空字符串评估为false,因此您将进入else部分 - 并在此过程中失去价值。

答案 2 :(得分:0)

你只有一个=符号

你需要:

if($community == '') { etc...