开发者

Using a while loop with objective oriented php programming

I am using the for each below with objective

$hierachy = new hierachy;
$iterator = new RecursiveIteratorIterator(new recursiveArrayIterator($hierachy->getSamelevelNode($name1)));
try {
   while($row = $hierachy->getSamelevelNode($name1)) {
  if(!isset($name1)) {
   $name1 = $row['left_node']+1; // First row = the node we searched from. First child's lft = lft+1.
  }
  if($row['left_node'] == $name1) { //This is a child of the searched node.
    echo $row['name'开发者_Go百科];
    $name1 = $row['right_node']+1; //next child's lft = this child's rgt + 1.
  }
} 

    }
catch(Exception $e)
    {
    echo $e->getMessage();
    }

I don't have a fecht_Array function inside the functions.php I want to know how can I connect the function below with the while loop above with the function below.

    public function getSamelevelNode($node_name){
$stmt = conn::getInstance()->prepare("SELECT name,left_node,right_node
FROM categories
WHERE left_node = right_node AND name = :node_name
");
$stmt->bindParam(':node_name', $node_name, PDO::PARAM_STR);

$stmt->execute();
return $stmt->fetchALL(PDO::FETCH_ASSOC);
}

right now I am having trouble to know what function from the function in the while loop can be used to Fetch the data. I tried fetchALL but it seems.

In other words my function and the while loop are not working together.


You don't need recursive iterator, since you haven't nested arrays, for this.

Just use

while ($row == $hierachy->getSamelevelNode($name1)) {
    // use $row here
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜