spires Posted August 24, 2006 Share Posted August 24, 2006 Hi, Can anyone tell me how to create a submenu?What i am trying to do is, have one dropdown with all of the categorys in, once you select the category, the second dropdown will have only the submenus to the selected category. E.GCrew = riggers bouncers door stafflaser = installtion = porductionetc.at the moment i can only get the sub category dropdown to have the full list, not not a list based on the main cat.Any idears please.[code]<?php$query = "SELECT * FROM category order by id DESC";$result = mysql_query($query) or die ("query 1 failed");$count = mysql_num_rows($result); $cat = '<select name="cat"> <option value="NULL" selected>- - - - - - - </option>'; while ($row = mysql_fetch_array($result)) { $category = $row['cat']; $cat .= '<option value="'.$category.'">'.$category.'</option>'; } $cat .= '</select>'; $query1 = "SELECT * FROM categories";$result1 = mysql_query($query1) or die ("query 3 failed");$count1 = mysql_num_rows($result1); $sub = '<select name="sub"> <option value="NULL" selected>- - - - - - - </option>'; while ($row1 = mysql_fetch_array($result1)) { $sub .= '<option value="'.$row1['sub'].'">'.$row1['sub'].'</option>'; } $sub .= '</select>';?>[/code]http://www.theeventorganiser.com/register.phpThanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/ Share on other sites More sharing options...
spires Posted August 24, 2006 Author Share Posted August 24, 2006 I think i just need a way to tell what category has been selected without hitting the submit button. Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-80081 Share on other sites More sharing options...
michaellunsford Posted August 24, 2006 Share Posted August 24, 2006 Sounds like a job for javascript. Here's a tutorial I found in google:http://www.quirksmode.org/js/options.html Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-80094 Share on other sites More sharing options...
hitman6003 Posted August 24, 2006 Share Posted August 24, 2006 Or use Barand's script, BaaSelect.http://members.aol.com/barryaandrew/baaselect/baaselectguide.html Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-80096 Share on other sites More sharing options...
Barand Posted August 25, 2006 Share Posted August 25, 2006 Thanks for the plug, HitmanThere are limitations with baaSelect. You need a db structure like this[pre]category subcategory---------- -------------catID --+ subcatID category | subcategory +-< catID[/pre]and catID and subcatID need to be numeric (int) Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-80122 Share on other sites More sharing options...
stefands Posted October 15, 2006 Share Posted October 15, 2006 First off: "baaselect" rocks!! ;D One question:How do you create 3 drop-downs from that code? That would really make my day!! ;D ;) Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-109171 Share on other sites More sharing options...
Barand Posted October 15, 2006 Share Posted October 15, 2006 Try this[code]<?phpinclude 'db.php'; // connection stuffinclude 'baaselect.php';$sel = new baaSelect();$sel->addSelect('cat', 'category', 'id', 'catname' , '', 1 , '-select category-' );$sel->addSelect('subcat', 'subcategory', 'subcat_id', 'subcategory' , 'cat_id', 1 , '-select subcategory-' );$sel->addSelect('product', 'prodname', 'prodno', 'proddesc' , 'subcat_id', 1 , '-select product-' );?><html><head><meta name="generator" content="PhpED Version 4.5 (Build 4513)"><title>Sample baaSelect</title><meta name="author" content="Barand"><?php $sel->makeScript();?></head><body><form><?php $sel->makeSelect('cat'); $sel->makeSelect('subcat'); $sel->makeSelect('product');?><br /><input type="submit" name="action" value="Submit"></form></body></html>[/code]This will create the test data[code]-- MySQL Administrator dump 1.4---- -------------------------------------------------------- Server version 5.0.18-nt/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;/*!40101 SET NAMES utf8 */;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;---- Create schema test--CREATE DATABASE /*!32312 IF NOT EXISTS*/ test;USE test;---- Table structure for table `test`.`category`--DROP TABLE IF EXISTS `category`;CREATE TABLE `category` ( `id` int(11) NOT NULL auto_increment, `catname` varchar(30) default NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;---- Dumping data for table `test`.`category`--/*!40000 ALTER TABLE `category` DISABLE KEYS */;INSERT INTO `category` (`id`,`catname`) VALUES (1,'Cat 1'), (2,'Cat 2'), (3,'Cat 3'), (4,'Cat 4'), (5,'Cat 5');/*!40000 ALTER TABLE `category` ENABLE KEYS */;---- Table structure for table `test`.`prodname`--DROP TABLE IF EXISTS `prodname`;CREATE TABLE `prodname` ( `prodno` int(11) NOT NULL auto_increment, `proddesc` varchar(20) default NULL, `subcat_id` int(11) default NULL, PRIMARY KEY (`prodno`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;---- Dumping data for table `test`.`prodname`--/*!40000 ALTER TABLE `prodname` DISABLE KEYS */;INSERT INTO `prodname` (`prodno`,`proddesc`,`subcat_id`) VALUES (1,'a',11), (2,'b',11), (3,'cc',21), (4,'dd',21), (5,'eee',31), (6,'fff',31), (7,'gggg',41), (8,'hhhh',12), (9,'jjjjjj',12), (10,'kkkkkk',13), (11,'mmmm',13), (12,'nnnnn',22), (13,'ppppp',22), (14,'qqq',32), (15,'rrrrrrr',31), (16,'ssssssss',41), (17,'ttttttt',41), (18,'uuuuuuuu',51), (19,'vvvvvvvvv',51);/*!40000 ALTER TABLE `prodname` ENABLE KEYS */;---- Table structure for table `test`.`subcategory`--DROP TABLE IF EXISTS `subcategory`;CREATE TABLE `subcategory` ( `subcat_id` int(10) unsigned NOT NULL, `subcategory` varchar(45) NOT NULL, `cat_id` int(10) unsigned NOT NULL, PRIMARY KEY (`subcat_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;---- Dumping data for table `test`.`subcategory`--/*!40000 ALTER TABLE `subcategory` DISABLE KEYS */;INSERT INTO `subcategory` (`subcat_id`,`subcategory`,`cat_id`) VALUES (11,'subcat 11',1), (12,'subcat 12',1), (13,'subcat 13',1), (21,'subcat 21',2), (22,'subcat 22',2), (31,'subcat 31',3), (32,'subcat 32',3), (41,'subcat 41',4), (51,'subcat 51',5);/*!40000 ALTER TABLE `subcategory` ENABLE KEYS */;/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-109207 Share on other sites More sharing options...
stefands Posted October 16, 2006 Share Posted October 16, 2006 Thank you so much Barand, that works great! ;D ;DHmm, I don't want to be pushing my luck here, but can you create 2 series of drop-downs on the same page?I could then use separate submit buttons for each group to define the resulting query... and save me an extra web page. Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-109630 Share on other sites More sharing options...
Barand Posted October 16, 2006 Share Posted October 16, 2006 Just use 2 baaSelect objects, 1 for each group Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-109682 Share on other sites More sharing options...
stefands Posted October 16, 2006 Share Posted October 16, 2006 Is this [code]$sel = new baaSelect();[/code] etc. and [code]$sel2 = new baaSelect();[/code] and so on? Sorry, I'm not into the jargon yet... Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-109724 Share on other sites More sharing options...
Barand Posted October 16, 2006 Share Posted October 16, 2006 That's it :) Quote Link to comment https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/#findComment-109752 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.