Jump to content


Photo

Need help with Drop down box - noob


  • Please log in to reply
2 replies to this topic

#1 ShopMAster

ShopMAster
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 09 July 2006 - 08:48 PM

How do you code a drop down box pulling the info from my mySQL database?

the table is called 'players'.  Thanks.

#2 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 09 July 2006 - 08:55 PM

OK. You basically have to get your data from the database and echo it in an HTML select menu. Like this:

<?php
// connect to your database here
$conn = mysql_connect("localhost", "dbuser", "dbpass");
mysql_select_db("dbname", $conn);

// Make the query
$sql = mysql_query("SELECT * FROM players");

// Start the html select menu
$html = '"<select name="player_menu" id="player_menu">";

// Echo the results in a loop and add each option
while($row = mysql_fetch_assoc($sql)) {
    $html .= '<option value="'.$row['player_id'].'">'.$row['player_name'].'</option>\n';
}

// End the html select menu
$html .= '</select>';

// Echo the select menu
echo $html;
?>

You may need to change some table/field names but it should work. :)

Hope that helps,

Niall
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#3 ShopMAster

ShopMAster
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 10 July 2006 - 02:34 PM

Thanks Gast!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users