fork download
  1. <?php
  2.  
  3. function buildSqlForNestingLevel($nestingLevel)
  4. {
  5. if ($nestingLevel < 2) {
  6. throw new Exception('Builder works only with 2 and more nesting levels');
  7. }
  8. $closingParenthesisCount = $nestingLevel - 1;
  9. $sql = "SELECT * FROM {$this->table} WHERE path = ? AND parent_id = (";
  10.  
  11. while (--$nestingLevel) {
  12. $sql .= "SELECT id FROM {$this->table} WHERE path = ?";
  13. if ($nestingLevel > 1) {
  14. $sql .= ' AND parent_id = (';
  15. }
  16. }
  17. $sql .= str_repeat(')', $closingParenthesisCount);
  18.  
  19. return $sql;
  20. }
  21.  
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Standard output is empty