MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 3rd, 2002, 04:37 PM
onesign onesign is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 10 onesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql tree

There is a table "menu"
| id | menu | parent_id |

How to get like this
Main
Company
---- We
---- What

Service
---- VIP
--------- Very VIP
--------- Bad

Product
---- Computers

and so on

Reply With Quote
  #2  
Old December 3rd, 2002, 05:12 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Explain in plain English what it is you wish to store in the database, and how you'd like to retireive the info (eg, what will you be presenting from the database?) Once you do that, I'll know what it is precisely that you want and can help you.

Reply With Quote
  #3  
Old December 3rd, 2002, 05:42 PM
onesign onesign is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 10 onesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
In database will be menu structure for site.
I'd like to make map of the site.

Is it clear?

Reply With Quote
  #4  
Old December 3rd, 2002, 06:29 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
If it's a menu, why do you need it in a database? I don't see quite what you're trying to do. You don't put "design" in a database, you put data, or content and leave the actual design in your pages.

Reply With Quote
  #5  
Old December 3rd, 2002, 06:48 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
This is what I did when I was creating a category tree. I first loaded all the entries into an array, then I used a recursive function for deciding which level each of the categories should be in, and in which order. It's actually pretty easy
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #6  
Old December 3rd, 2002, 07:20 PM
onesign onesign is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 10 onesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lindset
Are you really from Alta, Norway?
So, we are neighbour, I'm from Murmansk, Russian.
I even was in Alta somewhen, 7-8 years ago.
It was popular selling different Russian souvenirs in Norway.
Best wishes!

Quote:
I first loaded all the entries into an array, then I used a recursive function for deciding which level each of the categories should be in, and in which order. It's actually pretty easy

I'm trying to do the same, but it's not clear for me now.

Reply With Quote
  #7  
Old December 3rd, 2002, 07:31 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Quote:
Originally posted by onesign
Lindset
Are you really from Alta, Norway?
So, we are neighbour, I'm from Murmansk, Russian.
I even was in Alta somewhen, 7-8 years ago.
It was popular selling different Russian souvenirs in Norway.
Best wishes!


I'm trying to do the same, but it's not clear for me now.


Yep, I'm really from Alta, Norway

I'm going to bed now, but I'll see if I can post an example tomorrow, all right? Presuming you're using PHP, that is..

Reply With Quote
  #8  
Old December 4th, 2002, 03:06 AM
onesign onesign is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 10 onesign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It will be nice to see an example.
I'm using PHP.

Reply With Quote
  #9  
Old April 26th, 2007, 04:57 AM
HalitYesil HalitYesil is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 HalitYesil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 20 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by onesign
There is a table "menu"
| id | menu | parent_id |

How to get like this
Main
Company
---- We
---- What

Service
---- VIP
--------- Very VIP
--------- Bad

Product
---- Computers


PHP Code:
/*
 * Function get db menu and sub menu in array
 * @ param int parent_id
 * @ return array
 */
 
function get_menuq($p 0){
    
$p doubleval($p);
    
$Q = @ mysql_query("SELECT * FROM menu AS t1 WHERE t1.parent_id=".$p." ORDER BY t1.menu ASC");
    if(!
$Q) return false;
    if((
$S = @ mysql_num_rows($Q)) <= 0) return false;
    while(
$A = @ mysql_fetch_array($Q)){
        
$out[] = array(menu => $A,
                             
submenu => get_menuq($A['id']));
    }

    return 
$out;
 }
 
 
/*
 * Function tree array decore html string
 * @ param array get_menuq function out
 * @ return html string 
 */
 
function menu_html($a){
   if(!
is_array($a)) return false;
   
$out '<ul style="margin-left:5px;">';
   foreach(
$a as $s){
      
$out .='<li>';
      
$out .=$s['menu']['menu'].'<br>';
      if(
is_array($s['submenu'])) $out .= menu_html($s['submenu']);
      
$out .='</li>';
   }
   
$out .='</ul>';
 }

  
// get db menu tree array
  
$menuArray get_menuq($p 0);
  
  
//Decorate html tree array
  
echo menu_html($menuArray); 


Good luck..
---
by HalitYEŞİL
w w w . trteknik . n e t - w w w . mysqlturkiye . c o m

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql tree


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT