使用php将循环记录分配给单个变量

时间:2017-04-12 07:34:24

标签: php

我需要将所有循环记录转换为单个变量。我试过这个,但我得到了循环的最终记录。我如何获得所有记录。你能解决这个问题吗?在这里,我添加了我的代码,

$text = '';
    $sql = mysql_query("SELECT * FROM table WHERE column_name = 'column_value'");
    while($row = mysql_fetch_array($sql)){
      $text = '<li><div class="row">
                <div class="col-md-12 post">
                    <div class="row">
                        <div class="col-md-12">
                            <h5>
                                <strong><a href="'.$row['field1'].'.php" class="post-title">'.$row['field2'].'</a></strong></h4>
                        </div>
                    </div>

                    <div class="row post-content">

                        <div class="col-md-12">
                            <p style="margin-bottom:0px">

';
$text.= substr($row['field3'],0,150);



                            $text.= '...</p>

                                <a class="pull-right" href="'.$row['field2'].'.php">>> Read more</a>
                        </div>
                    </div>
                </div>
            </div></li>';
    }

1 个答案:

答案 0 :(得分:1)

您没有查看$text变量

$text = '';
while() { ...
  $text .= '<li>...'; // you missed this dot
}
echo $text;