LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 06-07-2003, 10:37 AM   #1
Gear_freak2000
Member
 
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

CAT1 (CAT)
-- BOB1 (LINK)
-- BOB2
-- BOB3

CAT2
-- BILL1
-- BILL2
-- BILL3

CAT3
-- 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
Member
 
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 php.net for that.

Code:
$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
Gear_freak2000
Member
 
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
atnonis
LQ Newbie
 
Registered: Oct 2005
Distribution: Slackware, Fedora, CentOS
Posts: 14

Rep: Reputation: 0
Quote:
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?

thanks
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:26 AM.

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