Jump to content

Recommended Posts

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.G
Crew = riggers
           bouncers
           door staff
laser = installtion
        = porduction
etc.

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.php


Thanks for your help
Link to comment
https://forums.phpfreaks.com/topic/18594-form-dropdowns-creating-submenues/
Share on other sites

Thanks for the plug, Hitman

There 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)
  • 1 month later...
Try this
[code]
<?php
include 'db.php'; // connection stuff
include '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]
Thank you so much Barand, that works great! ;D  ;D
Hmm, 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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.