Thanks again Matt, but I'm still not adding each loop to the $list[] array in the $Article object.
Here's the code:
class Article
{
static $list = array();
public function __construct( $data=array() ) {
if ( isset( $data['parentname'] ) ) $this->parentname = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['parentname'] );
}
public static function recureparent( $childnm ) {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "SELECT DISTINCT parentname
FROM parenttable
WHERE childname = :childnm";
$st = $conn->prepare( $sql );
$st->bindValue( ":childnm", $childnm, PDO::PARAM_STR );
$st->execute(); // call execute() to run the query
// $list = array();
while ( $row = $st->fetch() ) {
$Article = new Article( $row );
$list[] = $Article;
}
// Now get the total number from first
$sql = "SELECT FOUND_ROWS() AS totalRows";
$totalRows = $conn->query( $sql )->fetch();
$conn = null;
if ($list){
foreach ( $list as $findparent ) {
article::recureparent($findparent ->parentname);
}
} // end if list exist IF
return ( array ( "results" => $list, "totalRows" => $totalRows[0] ) );
} // End method
} // End Class
The resulting array:
Array ( [0] => Article Object ( [parentname] => Sydney ) )
The FOREACH works, an ECHO returns this list:
Sydney, New South Wales, Australia
Thanks again
philatnotable