Page 1 of 1

PHP beginner enquiry

Posted: Thu Dec 14, 2006 4:26 am
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]

Posted: Thu Dec 14, 2006 4:30 am
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.

Posted: Thu Dec 14, 2006 4:35 am
by mark16
theres no way to reference a drop down menu using php?

would you know of any good examples out there?

Thanks
Mark

Posted: Thu Dec 14, 2006 4:39 am
by malcolmboston

Posted: Thu Dec 14, 2006 4:42 am
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.

Posted: Thu Dec 14, 2006 4:45 am
by s.dot
malcolmboston wrote:Dynamic Drive
I found this, looking quickly: http://www.dynamicdrive.com/dynamicinde ... /index.htm

Posted: Thu Dec 14, 2006 4:53 am
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

Posted: Thu Dec 14, 2006 5:00 am
by mark16
thanks guys,
ill look into all that later, ill get back to ye with how i get on.

Thanks

Mark