- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
$path = "a/b/c/d";
$sections = array_reverse (explode ("/", $path));
$sql = "SELECT `t1`.`id` FROM ";
for ($i = 1; $i <= count ($sections); $i ++)
$from_tables[] = "`test` `t".$i."`";
$sql = $sql.implode (", ", $from_tables);
$sql .= " WHERE ";
for ($i = 1; $i < count ($sections); $i ++)
$sql .= "`t".$i."`.`parent_id` = `t".($i+1)."`.`id` AND `t".$i."`.`name` = '".$sections[$i-1]."' AND";
$sql .= " `t".count ($sections)."`.`parent_id` = '0' AND `t".count ($sections)."`.`name` = '".$sections[count($sections)-1]."'";
echo $sql;
guest 20.01.2009 15:45 # 0