Jump to content


Photo

form dropdowns, creating submenues.


  • Please log in to reply
10 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 24 August 2006 - 10:04 PM

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.
<?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>';
?>

http://www.theevento...om/register.php


Thanks for your help
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 24 August 2006 - 10:28 PM

I think i just need a way to tell what category has been selected without hitting the submit button.


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#3 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 24 August 2006 - 11:01 PM

Sounds like a job for javascript. Here's a tutorial I found in google:

http://www.quirksmod...js/options.html

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 24 August 2006 - 11:03 PM

Or use Barand's script, BaaSelect.

http://members.aol.c...electguide.html

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 25 August 2006 - 12:25 AM

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)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 stefands

stefands
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 15 October 2006 - 09:26 PM

First off: "baaselect" rocks!!  ;D
One question:
How do you create 3 drop-downs from that code? That would really make my day!!  ;D ;)

.:: who decides reason? .:...

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 15 October 2006 - 11:16 PM

Try this
<?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>

This will create the test data
-- 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 */;

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 stefands

stefands
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 16 October 2006 - 05:39 PM

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.
.:: who decides reason? .:...

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 16 October 2006 - 07:02 PM

Just use 2 baaSelect objects, 1 for each group
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 stefands

stefands
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 16 October 2006 - 08:42 PM

Is this
$sel = new baaSelect();
etc. and
$sel2 = new baaSelect();
and so on? Sorry, I'm not into the jargon yet...
.:: who decides reason? .:...

#11 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 16 October 2006 - 09:49 PM

That's it :)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users