PHP beginner enquiry

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mark16
Forum Newbie
Posts: 7
Joined: Thu Dec 14, 2006 4:13 am

PHP beginner enquiry

Post by mark16 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey Guys,
                Im  totally new to php, just started looking at it yesterday  , but im trying to make a simple page, basically 4 drop down menus of which 3 is locked untill an option is choosen in one, each menu will be populated depending on the choice of the drop down menu preceding it.
eg menu 1 chooses "staff",
menu 2 is now populated with staff categories such as managers, employees.
 so far ive managed to dynamically populate a drop down menu.

Code: Select all

<tr>
			<td><select size="1" name="DSquad">
                       <?php
                       $query2 = "SELECT DISTINCT Squad FROM Swimmers";
                       $squad=mysql_query($query2);
                       $num2=mysql_numrows($squad);
                       $i2=0;
                            while ($i2 < $num2) {
                                $squad2=mysql_result($squad,$i2,"Squad");
                       ?>
                       <option><?php echo "$squad2"; ?></option>
                         <?php $i2++; }?>
                       </select></td>
How would you suggest for me to populate the next drop down menu, i was think if statement, but im not sure how to do it with the html?

Any help appreciated

Mark


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You're looking for a javascript solution. :-D

If php is needed to pull the results from a database, then you'll want to have that information readily available for the javascript. Or, you could do some AJAX.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
mark16
Forum Newbie
Posts: 7
Joined: Thu Dec 14, 2006 4:13 am

Post by mark16 »

theres no way to reference a drop down menu using php?

would you know of any good examples out there?

Thanks
Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

If you want to reload the page (because the form is being submitted) after each dropdown box is selected, then yes, you can do it in PHP.

ex: User selects 'staff' from first box. Form is submitted (page is reloaded), data is pulled for second dropdown box by PHP and then populated by PHP. User selects 'employees' from second dropdown box. Form is submitted (page is reloaded), data is pulled for employees... and on and on like that.

It will work, but javascript would be a better solution, as it would provide for a nicer user experience.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

malcolmboston wrote:Dynamic Drive
I found this, looking quickly: http://www.dynamicdrive.com/dynamicinde ... /index.htm
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

I have also created a couple of topics on this, one pure javascript, the other recent one, using Ajax.
Javascript and Dynamic Select Boxes
Dynamic/Chained Selects using Ajax with Prototype
mark16
Forum Newbie
Posts: 7
Joined: Thu Dec 14, 2006 4:13 am

Post by mark16 »

thanks guys,
ill look into all that later, ill get back to ye with how i get on.

Thanks

Mark
Post Reply