![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Przyjaciele php.pl Postów: 2 335 Pomógł: 6 Dołączył: 7.03.2002 Ostrzeżenie: (0%) ![]() ![]() |
Mam sobie nastepujace drzewko w bazie:
/ck/ /ck/teatry /ck/teatry/Jakis teatr /ck/teatry/Jakis inny teatr I teraz musze na podstawie adresu - ForceType - np takiego: .../ck/teatry Sprawdzic czy w drzewie jest taki element i jezeli jest to pobrac jego ID. Struktura SQL wyglada tak: [sql:1:7b5ae2c8be]CREATE TABLE elements ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, class_id INT UNSIGNED NOT NULL, name VARCHAR(128), PRIMARY KEY(id) ); CREATE TABLE elements_relations ( first_id INT UNSIGNED NOT NULL, second_id INT UNSIGNED NOT NULL, depth INT UNSIGNED NOT NULL, PRIMARY KEY( first_id, second_id ) );[/sql:1:7b5ae2c8be] ... Gdzie w elements trzymam: nazwy elementow w drzewie oraz typ klasy - folder/news itp - a w relacjach: powiazania elementow w drzewie. Jest to prawie dokladnie to co przedstawil tutaj dragon: http://webdeveloper.pl/forum/read.php?f=3&...i=711&t=711&v=f Czyli jeszcze raz: jak na podstawie podanej sciezki odnalezc ID elementu na ktory ona wskazuje (sciezka) :?: |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Przyjaciele php.pl Postów: 1 467 Pomógł: 13 Dołączył: 22.02.2003 Ostrzeżenie: (0%) ![]() ![]() |
w klasie, którą właśnie kończe, wygląda to tak:[php:1:dccd66dbd3]<?php
class xxx //... protected function _exists() { $parts=explode("/", $this->_path); $parent=$this->_root; $this->_trans->start(); foreach($parts as $part) { if(!$part) continue; $name=$this->_adodb->Quote($part); $rs=$this->_adodb->Execute(sprintf($this->_getChildByNameSQL ,$name ,$parent)); if(!$rs)//Error (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) { $this->_error("DBERROR"); $this->_trans->rollback(TRUE); return NULL; } if($rs->RowCount()!=1)//No such node { return NULL; } $parent=intval($rs->fields[0]); $rs->Close(); } $this->_trans->commit(); $this->__id=$parent; return $parent; } protected $_getChildByNameSQL = "SELECT id FROM nodes WHERE name='%s' AND parent=%d;"; //... ?>[/php:1:dccd66dbd3]U Ciebie, jeżeli nie stosujesz pola parent wszystko kończy się na zmienieniu query (to będzie coś w rodzaju):[sql:1:dccd66dbd3]select nodes.id from nodes, asociations where nodes.id=asociations.second_id and asociations.depth=1 and nodes.name='%s' and asociations.first_id=%d[/sql:1:dccd66dbd3] |
|
|
![]() ![]() |
![]() |
Aktualny czas: 9.10.2025 - 05:42 |