473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

populate one menu from another

I thought this would be simple and there would be advice / tutorials
everywhere for this, but now that I'm working on it, I can't find any
reference except for ASP or Javascript code. PHP/MySQL - 3 form select
menus: Project, Categories, Subcategories. When a Project is selected, the
Categories list is populated based on Project selected, then Subcategories
list is populated based on Category selected. I see this all over the Net,
but through 10 books, there isn't anything specific. I think I get lost
with some of PHP structure since I've been using DW - I end up editing most
of it in order to follow it, but DW works pretty good for getting initial
testing done. I just can't seem to find further guidance on this. So far I
have:

<form enctype="multipart/form-data" action="add_file.php" method="post">
<table>

<tr>
<td width="23%" rowspan="2" valign="top"><p><strong>Project:<br />
</strong>
<select name="project">
<?php
do {
?>
<option value="<?php echo
$row_projects['projCode']?>"><?php echo $row_projects['projCode']?></option>
<?php
} while ($row_projects = mysql_fetch_assoc($projects));
$rows = mysql_num_rows($projects);
if($rows 0) {
mysql_data_seek($projects, 0);
$row_projects = mysql_fetch_assoc($projects);
}
?>
</select>
</p>
<p><strong>
Category:
<select name="category" id="category">
<option>Select a category...</option>
<option value="<?php echo $row_categories['catName']?>"><?php
echo $row_categories['catName']?></option>
<?php
do {
?>
<?php
} while ($row_categories = mysql_fetch_assoc($categories));
$rows = mysql_num_rows($categories);
if($rows 0) {
mysql_data_seek($categories, 0);
$row_categories = mysql_fetch_assoc($categories);
}
?>
</select>

</strong></p>
<p>

</p></td>
<td width="26%" valign="top"><p><strong>Subcategory:</strong>
<select name="subcategory" id="subcategory">
<option>Select a subcategory...</option>
<?php
if (isset('category'))
{
if ($row_subcat['catID']==$row_categories['catID'])
{
do
{?>
<option value="<?php echo $row_subcat['subcatName']; ?>"></option>
<?php
}
while ($row_subcat = mysql_fetch_assoc($subcat));
$rows = mysql_num_rows($subcat);
if($rows 0)
{
mysql_data_seek($subcat, 0);
$row_subcat = mysql_fetch_assoc($subcat);
}
}
}
}
?>
</select>

Thanks for any help with this.

Chris
Jul 10 '06 #1
5 2125
Mosf of the examples you have seen are probably using javascript, with
php you realise the page needs to reload when a cat is chosen? PHP
can't dynamically update the menu without loading the page again, you
would the user to choose a catergory, then have a submit button to post
the var or a link like page/index.php?cat1=$cat1 and so forth. Probably
recommend javascript for this though.

Flamer.
Chris wrote:
I thought this would be simple and there would be advice / tutorials
everywhere for this, but now that I'm working on it, I can't find any
reference except for ASP or Javascript code. PHP/MySQL - 3 form select
menus: Project, Categories, Subcategories. When a Project is selected, the
Categories list is populated based on Project selected, then Subcategories
list is populated based on Category selected. I see this all over the Net,
but through 10 books, there isn't anything specific. I think I get lost
with some of PHP structure since I've been using DW - I end up editing most
of it in order to follow it, but DW works pretty good for getting initial
testing done. I just can't seem to find further guidance on this. So far I
have:

<form enctype="multipart/form-data" action="add_file.php" method="post">
<table>

<tr>
<td width="23%" rowspan="2" valign="top"><p><strong>Project:<br />
</strong>
<select name="project">
<?php
do {
?>
<option value="<?php echo
$row_projects['projCode']?>"><?php echo $row_projects['projCode']?></option>
<?php
} while ($row_projects = mysql_fetch_assoc($projects));
$rows = mysql_num_rows($projects);
if($rows 0) {
mysql_data_seek($projects, 0);
$row_projects = mysql_fetch_assoc($projects);
}
?>
</select>
</p>
<p><strong>
Category:
<select name="category" id="category">
<option>Select a category...</option>
<option value="<?php echo $row_categories['catName']?>"><?php
echo $row_categories['catName']?></option>
<?php
do {
?>
<?php
} while ($row_categories = mysql_fetch_assoc($categories));
$rows = mysql_num_rows($categories);
if($rows 0) {
mysql_data_seek($categories, 0);
$row_categories = mysql_fetch_assoc($categories);
}
?>
</select>

</strong></p>
<p>

</p></td>
<td width="26%" valign="top"><p><strong>Subcategory:</strong>
<select name="subcategory" id="subcategory">
<option>Select a subcategory...</option>
<?php
if (isset('category'))
{
if ($row_subcat['catID']==$row_categories['catID'])
{
do
{?>
<option value="<?php echo $row_subcat['subcatName']; ?>"></option>
<?php
}
while ($row_subcat = mysql_fetch_assoc($subcat));
$rows = mysql_num_rows($subcat);
if($rows 0)
{
mysql_data_seek($subcat, 0);
$row_subcat = mysql_fetch_assoc($subcat);
}
}
}
}
?>
</select>

Thanks for any help with this.

Chris
Jul 10 '06 #2
Gary L. Burnore wrote:
On 10 Jul 2006 16:13:03 -0700, "flamer di******@hotmail.com"
<di******@hotmail.comtop posted like a moron and wrote:

>>Mosf of the examples you have seen are probably using javascript, with
php you realise the page needs to reload when a cat is chosen? PHP
can't dynamically update the menu without loading the page again, you
would the user to choose a catergory, then have a submit button to post
the var or a link like page/index.php?cat1=$cat1 and so forth. Probably
recommend javascript for this though.


The php code can generate the javascript code. Best of both "hello
worlds".

>>Flamer.
And you can generate javascript code without php, also.

You completely missed the point.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 11 '06 #3
Hi All,

I did find several Javascript-based sets of code, but knew I need something
where the JS controls the element but had no 'static' variables or arrays .
One of them has Javascript refresh the page, and another keeps the
visibility off of secondary listboxes until the primary one is selected. I
think I will try this one as the <optionscan be populated with PHP, then
the Javascript/CSS controls when they appear. I did this with a cascading
menu - where the JS/CSS only controlled the element (byID) and it worked
fine. If this works out, I will post the final code here.

Thanks,
Christina

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:Mp******************************@comcast.com. ..
Gary L. Burnore wrote:
>On 10 Jul 2006 16:13:03 -0700, "flamer di******@hotmail.com"
<di******@hotmail.comtop posted like a moron and wrote:

>>>Mosf of the examples you have seen are probably using javascript, with
php you realise the page needs to reload when a cat is chosen? PHP
can't dynamically update the menu without loading the page again, you
would the user to choose a catergory, then have a submit button to post
the var or a link like page/index.php?cat1=$cat1 and so forth. Probably
recommend javascript for this though.


The php code can generate the javascript code. Best of both "hello
worlds".

>>>Flamer.

And you can generate javascript code without php, also.

You completely missed the point.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 11 '06 #4
I have faced exactly the same problem:

Chose a region,then a county then a district...

Two choices with PHP without using javascript. First one is to present
each question one at a time and pass the values through the forms which
is a PITA!

Second one. Generate a single drop down list that looks like the
following:-

------Primary1
---Secondary1
Tertiary1
Tertiary2
Tertiary3
--Secondary2
Tertiary4
Terrary5
------Primary2
---Secondary3
Tertiary6
Tertiary7
and validate that the user has selected a valid tertiary value before
processing the form

If you want my code post a reply here and I will pm you

Obiron
Chris wrote:
Hi All,

I did find several Javascript-based sets of code, but knew I need something
where the JS controls the element but had no 'static' variables or arrays .
One of them has Javascript refresh the page, and another keeps the
visibility off of secondary listboxes until the primary one is selected. I
think I will try this one as the <optionscan be populated with PHP, then
the Javascript/CSS controls when they appear. I did this with a cascading
menu - where the JS/CSS only controlled the element (byID) and it worked
fine. If this works out, I will post the final code here.

Thanks,
Christina

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:Mp******************************@comcast.com. ..
Gary L. Burnore wrote:
On 10 Jul 2006 16:13:03 -0700, "flamer di******@hotmail.com"
<di******@hotmail.comtop posted like a moron and wrote:
Mosf of the examples you have seen are probably using javascript, with
php you realise the page needs to reload when a cat is chosen? PHP
can't dynamically update the menu without loading the page again, you
would the user to choose a catergory, then have a submit button to post
the var or a link like page/index.php?cat1=$cat1 and so forth. Probably
recommend javascript for this though.
The php code can generate the javascript code. Best of both "hello
worlds".
Flamer.
And you can generate javascript code without php, also.

You completely missed the point.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 12 '06 #5
<comp.lang.php>
<frothpoker>
<12 Jul 2006 06:02:20 -0700>
<11*********************@m79g2000cwm.googlegroups. com>
I have faced exactly the same problem:

Chose a region,then a county then a district...

Two choices with PHP without using javascript. First one is to present
each question one at a time and pass the values through the forms which
is a PITA!

Second one. Generate a single drop down list
You could use the ip address and store via a flatfile .

$skunk=$_SERVER['REMOTE_ADDR'];
$bjob=str_replace(".","_",$skunk);

$filename="demo/$bjob" . "_menu.php";
$fp=fopen($filename,"r");
$qaz=fgets($fp); $temp1=trim($qaz);
fclose($fp);

$filename="demo/$bjob" . "_demo.php";
$fp=fopen($filename,"r");
$qaz=fgets($fp); $temp1=trim($qaz);
fclose($fp);

read/write to suit etc .
--
Encrypted email address
www.emailuser.co.uk/?name=KRUSTOV
Jul 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: julian | last post by:
hi I was wondering if anyone can help me out on this.... I have dynamcally populated a drop down menu with data from an access database using ASP. The values seem fine, however when i pass...
6
by: Greg Scharlemann | last post by:
I am attempting to populate a drop down menu based on the selection of a different drop down menu. However, it is not working correctly, I cannot figure out for the life of me what exactly happens...
1
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop...
4
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display...
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
2
by: fiorea | last post by:
I have a cascading menu, which works great. Now I am trying to populate the menu from a databas, using ASP. If anyone can shed some light in this, please help. I can provide whatever code...
2
by: Vinnie | last post by:
When i try populate a dropdownlist menu using a for cycle i get a list of integers from ( in example ) 1 to 10. How can populate the same list, if working on the code (C#) i wish to get not longer...
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.