2010-05-18 25 views
5

से पेड़ दृश्य कैसे बनाएं, मुझे अपने mysql डेटाबेस में सहेजी गई मेरी श्रेणियों का एक वृक्षदृश्य दिखाने की आवश्यकता है।MySQL और PHP और jquery

डेटाबेस तालिका:

तालिका: बिल्लियों:

कॉलम: आईडी, नाम, माता-पिता समस्या php हिस्से में है:

//function to build tree menu from db table test1 
function tree_set($index) 
{ 
    global $menu; 
    $q=mysql_query("select * from cats where parent='$index'"); 
    if(!mysql_num_rows($q)) 
     return; 
    $menu .= '<ul>'."\n"; 
    while($arr=mysql_fetch_assoc($q)) 
    { 
     $menu .= '<li>'; 
     $menu .= '<span class="file">'.$arr['name'].'</span>';//you can add another output there 
     $menu .=tree_set("".$arr['id'].""); 
     $menu .= '</li>'."\n"; 
    } 

    $menu.= '</ul>'."\n"; 
return $menu; 

} 



//variable $menu must be defined before the function call 
$menu = ' 
<link rel="stylesheet" href="modules/Topics/includes/jquery.treeview.css" /> 
<script src="modules/Topics/includes/lib/jquery.cookie.js" type="text/javascript"></script> 
<script src="modules/Topics/includes/jquery.treeview.js" type="text/javascript"></script> 
<script type="text/javascript" src="modules/Topics/includes/demo/demo.js"></script> 
<ul id="browser" class="filetree">'."\n"; 
$menu .= tree_set(0); 
$menu .= '</ul>'; 
echo $menu; 

मैं भी इस मंच में पूछा गया: http://forums.tizag.com/showthread.php?p=60649

समस्या मेरे कोड के PHP भाग में है जिसका मैंने उल्लेख किया है। मैं उप मेन्यू नहीं दिखा सकता, मेरा मतलब है, वास्तव में मुझे नहीं पता कि उप मेन्यू कैसे दिखाएं

क्या प्रो पीएचपी कोडर की मदद करने का कोई मौका है?

+1

क्या आपकी समस्या, फिर से है पर टिप्पणी के आधार पर अपडेट किया गया:

मैं यह करने के अपने कार्य परिवर्तित करेंगे? आपने अभी कुछ कोड चिपकाया है लेकिन यह नहीं कहा कि आपकी समस्या वास्तव में क्या थी ... मुझे आशा है कि आप हमें जिस स्क्रिप्ट का उल्लेख करते हैं उसे डाउनलोड करने की उम्मीद नहीं कर रहे हैं, * अपनी समस्या को समझें *, और फिर मुफ्त में आपके लिए काम करें ... – Seb

उत्तर

3

ऐसा लगता है कि आप अपने मेनू चर में डुप्लिकेट डेटा भेज रहे हैं, जिसे वहां होने की आवश्यकता नहीं है।

function tree_set($index) 
{ 
    //global $menu; Remove this. 
    $q=mysql_query("select * from cats where parent='$index'"); 
    if(mysql_num_rows($q) === 0) 
    { 
     return; 
    } 

    // User $tree instead of the $menu global as this way there shouldn't be any data duplication 
    $tree = $index > 0 ? '<ul>' : ''; // If we are on index 0 then we don't need the enclosing ul 
    while($arr=mysql_fetch_assoc($q)) 
    { 
     $subFileCount=mysql_query("select * from cats where parent='{$arr['id']}'"); 
     if(mysql_num_rows($subFileCount) > 0) 
     { 
      $class = 'folder'; 
     } 
     else 
     { 
      $class = 'file'; 
     } 

     $tree .= '<li>'; 
     $tree .= '<span class="'.$class.'">'.$arr['name'].'</span>'; 
     $tree .=tree_set("".$arr['id'].""); 
     $tree .= '</li>'."\n"; 
    } 
    $tree .= $index > 0 ? '</ul>' : ''; // If we are on index 0 then we don't need the enclosing ul 

    return $tree; 
} 

//variable $menu must be defined before the function call 
$menu = '....<ul id="browser" class="filetree">'."\n"; 
$menu .= tree_set(0); 
$menu .= '</ul>'; 
echo $menu; 

सवाल

+0

क्या आप जेनरेट कर रहे एचटीएमएल का एक उदाहरण दिखा सकते हैं? – Nalum

+0

: डी धन्यवाद आपका स्लॉटियन पूरी तरह से सही था, लेकिन वर्तमान समस्या यह है कि, यह स्क्रिप्ट पेज के कुल प्रश्नों के लिए 23 प्रश्न जोड़ देगा, बस मेरे पास तालिका में 10 पंक्तियां हैं। क्या होगा यदि किसी के पास 40 पंक्तियां है तो भगवान उसे आशीर्वाद दें! क्या इस समस्या का दौर पाने का कोई तरीका है! –

+0

आप तालिका से पूछ सकते हैं और सरणी में स्थापित सभी पंक्तियां प्राप्त कर सकते हैं, फिर आवश्यक HTML बनाने के लिए सरणी पर लूप करें। – Nalum