Arkadaşlar Merhaba.
-id-baslik-icerik-ustsayfa-
-1-Ürünler-Ürünler Sayfası-0-
-2-Ürün1-Ürün1 Açıklaması-1-
şekliden db var.
ezsql kullanıyorum ve sayfaları ve altsayfaları listeleme fonksiyonu yazamadım. Aslında yazdımda if else ile 3 başlık altına kadar listeliyorum ancak 4. alt sayfada çıkmıyor kategori altkategori listeleme fonksiyonu ihtiyacım var yardımcı olursnız sevinirim.
Sınırsız Altsayfa Sistemi
4
●770
- 12-02-2013, 16:59:12Ben listeleme istiyorum.PsdBul adlı üyeden alıntı: mesajı görüntüle
Ürünler
|_>Ürün1
|_>Ürün2
Mağazalarımız
|_>Mağaza1
|_>Mağaza2
şeklinde.. - 12-02-2013, 18:07:51Kendimden örnek veriyorum editlersin..ulast adlı üyeden alıntı: mesajı görüntüle
index.php
<?php require "fonksiyon.php"; ?> <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script type="text/javascript"> function initMenus() { $('ul.menu ul').hide(); $.each($('ul.menu'), function(){ $('#' + this.id + '.expandfirst ul:first').show(); }); $('ul.menu li a').click( function() { var checkElement = $(this).next(); var parent = this.parentNode.parentNode.id; if($('#' + parent).hasClass('noaccordion')) { $(this).next().slideToggle('normal'); return false; } if((checkElement.is('ul')) && (checkElement.is(':visible'))) { if($('#' + parent).hasClass('collapsible')) { $('#' + parent + ' ul:visible').slideUp('normal'); } return false; } if((checkElement.is('ul')) && (!checkElement.is(':visible'))) { $('#' + parent + ' ul:visible').slideUp('normal'); checkElement.slideDown('normal'); return false; } } ); } $(document).ready(function() {initMenus();}); </script> <h3>Kategoriler</h3> <ul id="kategori" class="menu expandfirst"> <?php $htmlkod = ""; sayfagetir2(0,$htmlkod); echo $htmlkod; ?> </ul> <!-- Box Repeat -->fonksiyon.php
# Alt Var mı Yeni Kategori function altvarmi2($aitlik) { $select = "select * from category where kategori_ust_id = $aitlik "; $sorgu = mysql_query($select); $veri=mysql_fetch_array($sorgu); if($veri) return true; else return false; } # Alt Var mı Yeni Kategori # Yeni Kategori function sayfagetir2($aitlik = 0,&$menuler) { global $root; $select = "select * from category where kategori_ust_id = ".$aitlik." order by kategori_id desc"; $sorgu = mysql_query($select); while($veri=mysql_fetch_array($sorgu)) { if(altvarmi2($veri['kategori_id'])) { $menuler .= "<li>→<a href='#' class='solmenu'> ".$veri['kategori_adi']."<span style='float:right;padding-right:5px;'><img src='".$root."images/down.png' alt='Alt Kategorisini Görmek İçin Tıklayın..' /></span></a>\n"; } else { $menuler .= "<li>→ <a href='".$root."".sef_kategori($veri["sef"])."' class='solmenu'>".$veri['kategori_adi']."</a>\n"; } if(altvarmi2($veri['kategori_id'])) { $menuler .= "<ul>\n"; sayfagetir2($veri['kategori_id'],$menuler); $menuler .= "</ul>\n</li>\n"; } else { $menuler .= "</li>\n"; } } } # Yeni KategoriSQL
kategori_id | kategori_adi |title | sef |
Ekran Çıktısı
Ana Kategori
--Alt Ana Kategori
Ana Kategori2
--Alt Ana Kategori2
şeklinde accerdion menü yapmıştım buyur. - 12-02-2013, 18:51:37@samsunikinciel cevabın için teşekkür ederim. Ancak daha güzel bir fonksiyon buldum ;
<?php // Recursive function to generate a parent/child tree // Without the need for a Root parent // Written by: Brian Parnes // 13 March 2006 //$connect = mysql_connect(HOST_NAME, USERNAME, PASSWORD); //mysql_select_db(DATABASE); $nav_query = mysql_query("SELECT * FROM sayfa ORDER BY 'id'"); $tree = ""; // Clear the directory tree $depth = 1; // Child level depth. $top_level_on = 1; // What top-level category are we on? $exclude = array(); // Define the exclusion array array_push($exclude, 0); // Put a starting value in it while ( $nav_row = mysql_fetch_array($nav_query) ) { $goOn = 1; // Resets variable to allow us to continue building out the tree. for($x = 0; $x < count($exclude); $x++ ) // Check to see if the new item has been used { if ( $exclude[$x] == $nav_row['id'] ) { $goOn = 0; break; // Stop looking b/c we already found that it's in the exclusion list and we can't continue to process this node } } if ( $goOn == 1 ) { $tree .="<li><a href='#'>". $nav_row['baslik'] . "</a>"; // Process the main tree node array_push($exclude, $nav_row['id']); // Add to the exclusion list if ( $nav_row['id'] < 6 ) { $top_level_on = $nav_row['id']; } $tree .= build_child($nav_row['id']); // Start the recursive function of building the child tree $tree .='</li>'; } } function build_child($oldID) // Recursive function to get all of the children...unlimited depth { global $exclude, $depth; // Refer to the global array defined at the top of this script $child_query = mysql_query("SELECT * FROM sayfa WHERE altsayfa=" . $oldID); while ( $child = mysql_fetch_array($child_query) ) { if ( $child['id'] != $child['altsayfa'] ) { for ( $c=0;$c<$depth;$c++ ) // Indent over so that there is distinction between levels { $tempTree .= "<ul>"; } $tempTree .= "<li><a href='#'>" . $child['baslik'] . "</a></li>"; $depth++; // Incriment depth b/c we're building this child's child tree (complicated yet???) $tempTree .= build_child($child['id']); // Add to the temporary local tree $depth--; // Decrement depth b/c we're done building the child's child tree. array_push($exclude, $child['id']); // Add the item to the exclusion list for ( $c=0;$c<$depth;$c++ ) // Indent over so that there is distinction between levels { $tempTree .= "</ul>"; } } } return $tempTree; // Return the entire child tree } echo '<ul>'; echo $tree; echo '</ul>'; ?>tam istediğim gibi listeleme yapıyor.
<ul> <li>Menü 1</li> <li>Menü 2</li> <li>Menü 3 <ul> <li>Alt Menü1</li> <li>Alt Menü2</li> </ul> </li> </ul>
şeklinde..