开发者

While in a Class to Show Posts

i have a class lets call it page and it retrieve somw rows from database (array) and returns them. i want somthing like this: when a class called in a div (<div> $posts->show()</div>) like wordpress and other CMSs i want the div to be looped.i mean like

<div>1</div>开发者_运维知识库;<div>2</div><div>3</div><div>4</div>

within the class.


If I understood you: try this

 $i = 0;
    $table = null;
    while($row = mysql_fetch_array($your_query))
    {
        $table .= "<div>".$i++."  {$row[0]}</div>";
    }

    echo $table; 


This should put

1</div><div>2</div><div>3</div><div>4

between your div tags:

$i = 1;
$a = array();
while($row = mysql_fetch_array($query)) {
  array_push($a, $i);
}
echo implode('</div><div>', $a);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜