Vacman Posted June 9, 2008 Share Posted June 9, 2008 What I am doing is pulling these items from the db, but I would like to do one more thing before the pulldown menu is displayed.... In this particular case, I want to check to see what the current Team Division is and then display the Current Division as the default or first Division listed in the pulldown menu. In other words, pull all the Divisions from the db table, check to see what the current division that I working with and have that division listed as the first item visible in the pulldown. I hope this makes sense. Here is my code currently: ===================== PHP Code: $db_name = "my_db"; $table_name = "youth_divisions"; $connection = @mysql_connect("localhost", "my_name", "my_password") or die (mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $sql = "SELECT id, youth_div_name FROM $table_name ORDER BY youth_div_name DESC"; $result = @mysql_query($sql, $connection) or die(mysql_error()); $num = @mysql_num_rows($result); if ($num < 1) { $display_block="<P><em>Sorry, but there is a problem with my code writing skills!<P> Give Carl a call<BR>check_active_youth.php<P></em></P>"; } else{ while ($row=mysql_fetch_array($result)){ $id=$row['id']; $youth_div_a[$id] = $row['youth_div_name']; $youth_div_name=$row['youth_div_name']; $option_block.="<option value=\"$id\">$youth_div_name</option>"; } $display_block="<FORM METHOD=\"POST\" ACTION=\"check_active_youth.php\"> <P> <P><center><strong>Select a Youth Division: </strong> <select name=\"youth_division\">$option_block </select> <INPUT TYPE=\"SUBMIT\" NAME=\"submit\" VALUE=\"View Youth\"></P> </form>"; Link to comment https://forums.phpfreaks.com/topic/109355-populating-a-pulldown-menu-from-mysql-php/ Share on other sites More sharing options...
tippy_102 Posted June 9, 2008 Share Posted June 9, 2008 How do you know what the current Team Division is? Is it set in the database, or are you clicking a link for it on the previous web page? Link to comment https://forums.phpfreaks.com/topic/109355-populating-a-pulldown-menu-from-mysql-php/#findComment-560883 Share on other sites More sharing options...
Vacman Posted June 9, 2008 Author Share Posted June 9, 2008 How do you know what the current Team Division is? Is it set in the database, or are you clicking a link for it on the previous web page? I should have explained that. Yes it is passed (successfully) from a previous page.... But more specifically what I am looking at doing is to retrieve something like this: Name, address, phone, division, team, etc.. When the record is retrieved, the player's division is shown as part of a pull-down menu that also contains the other divisions in the league that they would be able to change to. These divisions are already established in the DB (in another table). So I want to pull their specific division, show it as the first item in the pull-down, and populate with the other divisions. If division is changed, that selected change would be reflected when the record is updated. I have no trouble pulling the complete list from the db, but I don't know how to go that last step. Thanks for looking! -Carl (Vacman) Link to comment https://forums.phpfreaks.com/topic/109355-populating-a-pulldown-menu-from-mysql-php/#findComment-560886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.