לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #4  
ישן 27-07-2008, 10:48
  משתמש זכר vadim88 vadim88 אינו מחובר  
 
חבר מתאריך: 14.04.06
הודעות: 331
בתגובה להודעה מספר 3 שנכתבה על ידי danielovadia שמתחילה ב "מה הכוונה לבדוק אם יש לכל ID..."

משהו כזה יעבוד כפי שאתה רוצה. נניח ויש לך טבלה של קטגוריות עם ID PARENTID TITLE כשדות.

קוד PHP:
<?php

// Recursive function to generate a parent/child tree

//$connect = mysql_connect(HOST_NAME, USERNAME, PASSWORD);
//mysql_select_db(DATABASE);
$nav_query mysql_query("SELECT * FROM `categories` ORDER BY `category_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($exclude0);    // 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['category_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 == )
    {
        
$tree .= $nav_row['title'] . "<br>";                // Process the main tree node
        
array_push($exclude$nav_row['category_id']);        // Add to the exclusion list
        
if ( $nav_row['category_id'] < )
        { 
$top_level_on $nav_row['category_id']; }
        
        
$tree .= build_child($nav_row['category_id']);        // Start the recursive function of building the child tree
    
}
}

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 `categories` WHERE parent_id=" $oldID);
    while ( 
$child mysql_fetch_array($child_query) )
    {
        if ( 
$child['category_id'] != $child['parent_id'] )
        {
            for ( 
$c=0;$c<$depth;$c++ )            // Indent over so that there is distinction between levels
            
$tempTree .= "&nbsp;"; }
            
$tempTree .= "- " $child['title'] . "<br>";
            
$depth++;        // Incriment depth b/c we're building this child's child tree  (complicated yet???)
            
$tempTree .= build_child($child['category_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['category_id']);            // Add the item to the exclusion list
        
}
    }
    
    return 
$tempTree;        // Return the entire child tree
}

echo 
$tree;

?>
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 20:09

הדף נוצר ב 0.03 שניות עם 12 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2025 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר