Lookup MySQL with a dropdown field

  • ACD Partner
  • Born
  • Born
  • ACD Partner
  • Posts: 4

Post 3+ Months Ago

Is it possible to create a form drop down field that gets it's values from a MySQL database rather than entering the options into the field script?
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

This is an example of one I used to dynamically manage fields that games could be played at.

PHP Code: [ Select ]
$fieldq = "SELECT * FROM fields ORDER BY field ASC";
$fieldr = mysql_query($fieldq);
while($fi=mysql_fetch_array($fieldr)){
 echo "<option value=\"$fi[field]\">$fi[field]</option>/n";
}
 
  1. $fieldq = "SELECT * FROM fields ORDER BY field ASC";
  2. $fieldr = mysql_query($fieldq);
  3. while($fi=mysql_fetch_array($fieldr)){
  4.  echo "<option value=\"$fi[field]\">$fi[field]</option>/n";
  5. }
  6.  


And here is it being modified and showing the previous entry:

PHP Code: [ Select ]
$fieldq = "SELECT * FROM fields ORDER BY field ASC";
$fieldr = mysql_query($fieldq);
while($fi=mysql_fetch_array($fieldr)){
 if($sm[field] == $fi[field]) { //sm[field] is the current data in the table
    echo "<option value=\"$fi[field]\" selected>$fi[field]</option>/n";
 } else {
    echo "<option value=\"$fi[field]\">$fi[field]</option>/n";
 }
}
 
  1. $fieldq = "SELECT * FROM fields ORDER BY field ASC";
  2. $fieldr = mysql_query($fieldq);
  3. while($fi=mysql_fetch_array($fieldr)){
  4.  if($sm[field] == $fi[field]) { //sm[field] is the current data in the table
  5.     echo "<option value=\"$fi[field]\" selected>$fi[field]</option>/n";
  6.  } else {
  7.     echo "<option value=\"$fi[field]\">$fi[field]</option>/n";
  8.  }
  9. }
  10.  
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8413
  • Loc: USA

Post 3+ Months Ago

neksus wrote:
This is an example of one I used to dynamically manage fields that games could be played at.

PHP Code: [ Select ]
$fieldq = "SELECT * FROM fields ORDER BY field ASC";
$fieldr = mysql_query($fieldq);
while($fi=mysql_fetch_array($fieldr)){
 echo "<option value=\"$fi[field]\">$fi[field]</option>/n";
}
 
  1. $fieldq = "SELECT * FROM fields ORDER BY field ASC";
  2. $fieldr = mysql_query($fieldq);
  3. while($fi=mysql_fetch_array($fieldr)){
  4.  echo "<option value=\"$fi[field]\">$fi[field]</option>/n";
  5. }
  6.  


And here is it being modified and showing the previous entry:

PHP Code: [ Select ]
$fieldq = "SELECT * FROM fields ORDER BY field ASC";
$fieldr = mysql_query($fieldq);
while($fi=mysql_fetch_array($fieldr)){
 if($sm[field] == $fi[field]) { //sm[field] is the current data in the table
    echo "<option value=\"$fi[field]\" selected>$fi[field]</option>/n";
 } else {
    echo "<option value=\"$fi[field]\">$fi[field]</option>/n";
 }
}
 
  1. $fieldq = "SELECT * FROM fields ORDER BY field ASC";
  2. $fieldr = mysql_query($fieldq);
  3. while($fi=mysql_fetch_array($fieldr)){
  4.  if($sm[field] == $fi[field]) { //sm[field] is the current data in the table
  5.     echo "<option value=\"$fi[field]\" selected>$fi[field]</option>/n";
  6.  } else {
  7.     echo "<option value=\"$fi[field]\">$fi[field]</option>/n";
  8.  }
  9. }
  10.  

You might need to use curly brackets "{...}"
PHP Code: [ Select ]
$fieldq = "SELECT * FROM fields ORDER BY field ASC";
$fieldr = mysql_query($fieldq);
while($fi=mysql_fetch_array($fieldr)){
 echo "<option value=\"{$fi[field]}\">{$fi[field]}</option>/n";
}
 
  1. $fieldq = "SELECT * FROM fields ORDER BY field ASC";
  2. $fieldr = mysql_query($fieldq);
  3. while($fi=mysql_fetch_array($fieldr)){
  4.  echo "<option value=\"{$fi[field]}\">{$fi[field]}</option>/n";
  5. }
  6.  

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 36 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.