• 05-11-2009, 23:13:57
    #1
    Selamlar arkadaşlar bir script kodladım ama içinden çıkamadığım birşey var.

    kategoriler tek tabloda bulunuyor ve sınırsır kategorileme var.

    Şöyle ki;
    kat_id kat_adi kat_sef ustkat_id
    1 aaa asef 0
    2 bbb bsef 1
    3 ccc csef 1
    4 ddd dsef 2
    5 eee esef 3
    6 ffff fsef 4

    gibi,

    kateogriye ile şöyle giriliyor. 6 nolu kategori için
    siteadi. com/asef/bsef/dsef/fsef (yani üst kategoriler yine

    şimdi yapamadığım şey.

    En son kategoriye girdiğimde yada herhangi bir kategoriye girdiğimde dahil olduğu tüm üst kategorileri alarak yazdırmak istiyorum.

    Anasayfa => aaa => bbb => ccc => ddd => eee olarak sıralamak istiyorum


    Bir türlü çözemedim... Lütfen yardım edin...
  • 05-11-2009, 23:40:00
    #2
    Üyeliği durduruldu
    string ile gönderdigin degeri sutundan kontrol edeceksin ve ekrana yazacaksın

    $id=$_GET["hoba"];

    sql// where yea='$id'
  • 06-11-2009, 00:40:35
    #3
    Nasıl yani hocam anlamadım,

    sadece bir üst kategoriyi almak istemiyorum silsile içerisinde ki tüm kategorileri almak istiyorum.

    kategoriler şöyle ise;

    Anakategori
    --altkat
    ---atkat2
    ----altkat3
    -----altkat4

    Ben altkat6 ya tıkladığımda şöyle gönderiyorum surguyu
    kat.php?katsef=altkat6

    Bu sayfa açıldığında görünmesini istediğim yazı,

    Anasayfa => Anakategori => altkat => altkat2 => altkat3 =>altkat4 yazısının görünmesini istiyorum.

    altkat4 e girdiğinde sadece 1 üstü almak kolay ama işte üstün üstünü ve ünun üstlerini nasıl alacağım...
  • 06-11-2009, 00:58:26
    #4
    Üyeliği durduruldu
    Merhaba, senin için 4-5 dakikamı ayırarak fonksiyon yazdım, anlattığın hiyeraşik yapı derin olduğu için sistem döngü içinde bir kaç işlem ile çalışıyor, kodlar karışık görünebilir.

    function kat_sirala($kat_sef, $kat_id = NULL)
    {
        $sira_ayrac = '=>';
        
        if ($kat_sef <> NULL)
            $kosul = sprintf("kat_sef = '%s'", $kat_sef);
        else
            $kosul = sprintf("kat_id = '%s'", $kat_id);
             
        $kat = mysql_fetch_array(mysql_query("SELECT * FROM kat WHERE {$kosul}"));
        $katlist[] = $kat['kat_adi'];
        
        for ($i = 0; $i < 10; $i++) {
            if (!is_array($katidlist)) 
                $ustkatid = $kat['ustkat_id'];
             else {
                if (!$katidlist[1]) {
                    $ustkatid = $katidlist[0];
                } else {
                    $ustkatid = $katidlist[count($katidlist) - 1];
                }
            }
            if ($ustkatid == 0) 
                break;
            else {
                $kat = mysql_fetch_array(mysql_query("SELECT * FROM kat WHERE kat_id = '" . $ustkatid . "'"));
                $katlist[]   = $kat['kat_adi'];
                $katidlist[] = $kat['ustkat_id'];
            }
        }
        for ($i = count($katlist) - 1; $i >-1; $i--) {
            $kliste[] = $katlist[$i];
        }
        $anasayfa = "Anasayfa {$sira_ayrac} ";
        $sira     = join(" {$sira_ayrac} ", $kliste);
        
        if ($sira <> NULL) {
            return $anasayfa . $sira;
        }
        return FALSE;
    }
    kullanım;
    // http://xxx.com/?katsef=fsef
    if ($_GET['katsef'])
    {
        echo kat_sirala($_GET['katsef']);
    }
    çıktı;
    Anasayfa => aaa => bbb => ddd => fff
    bazı kısımları kendine göre değiştirebilirsin mesela $sira_ayrac değişkenini. kolay gelsin.
  • 06-11-2009, 11:00:32
    #5
    Allah razı olsun hocam hemen deniyorum...
  • 06-11-2009, 11:03:18
    #6
    Kimlik doğrulama veya yönetimden onay bekliyor.
    <?php
    // $node is the name of the node we want the path of
    function get_path($node) {
       // look up the parent of this node
       $result = mysql_query('SELECT parent FROM tree '.
                              'WHERE title="'.$node.'";');
       $row = mysql_fetch_array($result);
    
       // save the path in this array
       $path = array();
    
       // only continue if this $node isn't the root node
       // (that's the node with no parent)
       if ($row['parent']!='') {
           // the last part of the path to $node, is the name
           // of the parent of $node
           $path[] = $row['parent'];
    
           // we should add the path to the parent of this node
           // to the path
           $path = array_merge(get_path($row['parent']), $path);
       }
    
       // return the path
       return $path;
    }
    ?>
    http://articles.sitepoint.com/articl...-data-database
  • 06-11-2009, 11:16:23
    #7
    Üyeliği durduruldu
    direk sql ile uygulamasi için şu makalede iş görebilir ingilizce ama aynısını çeviri olarak adres hatirlamiyorum Türk sitelerde görmüştüm
    http://dev.mysql.com/tech-resources/...ical-data.html
  • 06-11-2009, 14:19:18
    #8
    Üyeliği durduruldu
    @dnmknin verdiği kodda ise biraz değişiklik lazım, yani şu şekilde istediğini yapar;
    // $node is the name of the node we want the path of
    function get_path($node) {
       // look up the parent of this node
       $result = mysql_query("SELECT * FROM kat WHERE kat_id = '$node'");
       $row = mysql_fetch_array($result);
    
       // save the path in this array
       $path = array();
    
       // only continue if this $node isn't the root node
       // (that's the node with no parent)
       if ($row['ustkat_id'] != 0) {
           // the last part of the path to $node, is the name
           // of the parent of $node
           $path[] = $row['kat_adi'];
    
           // we should add the path to the parent of this node
           // to the path
           $path = array_merge(get_path($row['ustkat_id']), $path);
       }
       // return the path
       return $path;
    }
    kategori listesini array içine alır. örneğin kat_sef değeri olarak fsef gönderip o kategorinin üst kategorilerin array çıktısının içeriğini şu kodla görmek istediğimde
    $katlist = get_path('fsef');
    print_r($katlist);
    çıktısı aşağıdaki gibi olur;
    Array
    (
        [0] => aaa
        [1] => bbb
        [2] => ddd
        [3] => fff
    )
    bu array'i foreach ile istediğin şekilde çıkarıp biçimlendirip kullanabilirsin.
    ayrıca sdemirkeser in verdiği linkteki sql sorgusuda işini görür kolay gelsin.