tags:

views:

53

answers:

2

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.

+1  A: 

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; 
Dezigo
there's a missing parenthesis on the while
Jeriko
yes..thx I fixed it
Dezigo
A: 

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);
Luc
thanks i'll give it a try.
SNAKY
ok this works but i want to get mysql result from a classlike:while(have_posts()){echo $theclass->ID;}which the have_posts() function detects if the Class ID (a var) is less than the mysql_num_rows or notmy actuall problem is to set the ID in the class and return it in a while outside the class
SNAKY
i figured it out.thanks
SNAKY