Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-07-2003, 10:37 AM   #1
Registered: Jun 2003
Posts: 90

Rep: Reputation: 15
Mysql + php = Menu system

Hey.... My first post... So hey to everyone !

ok... now the question....

What i want is to create menu that gets all its information from a database.... (easy)

But..... what i cant work out how to do is list things under categories....

let me explain some more...

say i have

-- BOB1 (LINK)
-- BOB2
-- BOB3

-- BILL1
-- BILL2
-- BILL3

-- James1
-- James2
-- James3

i could do this by having a table for each CAT... But thats not what i want .

I want to have all the links and CATS in 1 table... and i want to be able to easily reorder the cats and links.

So i had this idea:

CAT1 (type=1, pos=1.0)
-- BOB1 (type=0, pos=1.1)
-- BOB2 (type=0, pos=1.2)
-- BOB3 (type=0, pos=1.3)

CAT2 (type=1, pos=2.0)
-- BILL1 (type=0, pos=2.1)
-- BILL2 (type=0, pos=2.2)
-- BILL3 (type=0, pos=2.3)

CAT3 (type=1, pos=3.0)
-- James1 (type=0, pos=3.1)
-- James2 (type=0, pos=3.2)
-- James3 (type=0, pos=3.3)

To explain:

So.... type=1 lets sql/php know that its a CAT and type=0 lets it know that its a link....

pos = the position of the cat and the position of the link within the cat.... (still with me?)....

But i just cant understand how i will write the code to make this all work.....

Thanks ALOT for any help anyone can give me!
Old 06-08-2003, 06:37 AM   #2
Obi Perrin
Registered: Nov 2002
Posts: 136

Rep: Reputation: 15
If I were doing this, I'd do it as two different tables. One named 'categories' and the other named 'subcategories'. Inventive huh?

In standard notation, each of the tables would be as following:

CATEGORIES(categoryid, name, position)
SUBCATEGORIES(subcategoryid, categoryid, subname, subposition)

So all categories would go in the categories table, and have a categoryid associated with them. When you're adding sub-categories to the database, the categoryid field in subcategories is filled in with the categoryid number of the category you want to add it to.

So your first step is to make these tables and fill them up with some data. Now comes the php script. I'm assuming you've covered some basic php and will hence focus on the more important sql/logical issues than syntax/commands. There's an excellent beginners tutorial at for that.

$sql = "SELECT * FROM categories, subcategories WHERE categories.categoryid = subcategories.categoryid ORDER BY categories.position, subcategories.subposition";

$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
This would return all the menu entries in the two tables in the order we want them. What you need to do now is use a loop to iterate though all of the results until there are no more left, at which point the menu has ended.

Hope this helps somehow
Old 06-08-2003, 07:05 AM   #3
Registered: Jun 2003
Posts: 90

Original Poster
Rep: Reputation: 15
thanks for the reply.... i managed to do it myself ! he he....
Old 02-26-2009, 08:10 AM   #4
LQ Newbie
Registered: Oct 2005
Distribution: Slackware, Fedora, CentOS
Posts: 14

Rep: Reputation: 0
Originally Posted by Gear_freak2000 View Post
thanks for the reply.... i managed to do it myself ! he he....
can u please post the solution?



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql-server4.1 and mod php-mysql conflig kernelvn *BSD 0 06-18-2005 11:52 AM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 08:54 PM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 02:54 PM
Apache Mysql Php: mysql with php doesn't work breakerfall Linux - Networking 6 12-27-2003 08:59 PM
php nuke - mysql and system user awbassett1 Linux - Software 0 06-17-2003 09:24 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:17 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration