Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,694 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,314 people online right now. Registration is fast and FREE... Join Now!




PHP Select Form

 
Reply to this topicStart new topic

PHP Select Form

elDeuce
post 28 May, 2008 - 09:13 AM
Post #1


New D.I.C Head

*
Joined: 28 May, 2008
Posts: 6

Here is what I have so far.

CODE

<select name="DesignerSupervisor" id="DesignerSupervisor">
  <option selected="selected">Choose One...</option>
    <?
      $sql_result = "SELECT SuperName FROM supervisors";
                        
       while ($row = mysql_fetch_array($sql_result)) {
         extract($row);
     echo "<option value='$name'>$name</option>";
       }
     ?>
</select>


I am extremely new to PHP and I am trying to make it where it will grab the SuperName from the supervisors table no matter how many names are in there and then setup an option for each one.

Obviously this doesn't work yet, it's a combination of stuff I have found on this board and some others.
If anyone has any pointers it would be appreciated.

This isn't homework, it's not for work work, it's me trying to teach myself PHP and being too poor to afford a decent book because gas is too damned expensive.

I'm not looking for you to solve it and write the code for me, but someone who can help out would be appreciated.

Thanks!
User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 28 May, 2008 - 09:24 AM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,062



Thanked 177 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Well you are very close. I just wouldn't use the extract() function because it could become a problem for security. But this should work for you granted you have a database linked up etc. The second part is that you actually have to query the database using mysql_query(). This executes the command on the database and returns the result set...

php

<?php
// Use mysql_query to query the database
$sql_result = mysql_query("SELECT SuperName FROM supervisors");

// Loop through the records and for each record store SuperName into the $name variable.
while ($row = mysql_fetch_array($sql_result)) {
$name = $row["SuperName"];
echo "<option value='$name'>$name</option>";
}
?>


Hope this works for you. Let us know if you have any further problems with it.

Enjoy!

"At DIC we be supername retrieving code ninjas...that and we are just plain 'Super' to begin with. We even have a 'Super' sloth. How many boards can claim that?" decap.gif
User is offlineProfile CardPM

Go to the top of the page

elDeuce
post 28 May, 2008 - 09:53 AM
Post #3


New D.I.C Head

*
Joined: 28 May, 2008
Posts: 6

Awesome!
I added a mysql_select_db() statement in there and it pulled up perfectly.

Your way makes a lot more sense then what I was trying to do.

I appreciate the help!
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:45AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month